Invisible text in QTextEdit - c++

I am learning Qt and running examples from Qt SDK 5.9.1. I run the code below and write inside QTextEdit but no text appears. Cursor moves as I write but no text is shown. Window title text is shown. I added addApplicationFont and setFont calls below I found from web to the sample but it didn't help.
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QFontDatabase::addApplicationFont("://Ubuntu-R.ttf");
app.setFont(QFont("Ubuntu", 11, QFont::Normal, false));
QTextEdit textEdit;
textEdit.show();
return app.exec();
}
I am on Ubuntu 16.04 and run following commands on bash to make executable:
qmake -makefile
make
./part1
I want the app to use the default Ubuntu system font. I learned that Qt uses fontconfig for fonts but I don't know how to trace the issue.
Edit
I thought QFontDatabase::addApplicationFont("://Ubuntu-R.ttf") call referenced system font but instead it is referencing font app resource file. I don't have resource file so obviously it won't work.
.pro file is below(unmodified sample file):
QT += widgets
SOURCES = main.cpp
# install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/gettingStarted/gsQt/part1
INSTALLS += target
I tried to get system font using QFontDatabase but it didn't work:
app.setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
This doesn't do anything with any of enum values including QFontDatabase::GeneralFont
QFontDatabase database;
QStringList fam = database.families();
fam size is zero.
I will try to use embedded font next.

I don't know the exact reason of the problem but the reason was not configuring fontconfig dependency properly before building qt. I solved it by reconfiguring and recompiling qt again. You can find more details at qt forum.

Related

Why are my qt file dialogs rendered incorrectly?

I'm currently creating a GUI with Qt 5.6 and I want to let the user open a file. I do this using the following code in my main window class:
#include <QFileDialog>
...
void MainWindow::loadScene()
{
QString loadPath = QFileDialog::getOpenFileName(this,
tr("Choose a scene file"), QString("."),
tr("Scene files (*.keyScene)"));
if(!loadPath.isEmpty())
resourceManager->loadScene(loadPath.toStdString());
}
I get the following dialog:
Screenshot of open file dialog
The system I use is Ubuntu 16.04, I've also tested on Ubuntu 14.04 and Mint 17.3. I get the exact same result on all of them.
When I compile the project in Windows everything works fine.
EDIT
It was suggested I play around with the DontUseNativeDialog flag when creating a file dialog, I can get a working Qt style file dialog with the following code:
QFileDialog dialog(this);
dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setOption(QFileDialog::Option::DontUseNativeDialog, true);
if(!dialog.exec())
return;
So the question is actually why native file dialogs aren't rendered correctly.

Add Settings entry for iOS app using Qt 5.4

I have built an iOS 8.2 app using Qt 5.4. I want to add a user-entry field in the Settings app like a lot of other apps do, but I can't figure out how to do it. I tried the following (which doesn't work):
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
TDA::TapDisplaySingleton* mainClass =
new TDA::TapDisplaySingleton(&app);
QObject::connect(&app, SIGNAL(aboutToQuit()),
mainClass, SLOT(aboutToQuitApp()));
QGuiApplication::setOrganizationName("NASA Langley");
QGuiApplication::setOrganizationDomain("larc.nasa.gov");
QGuiApplication::setApplicationName("TAP Display");
QSettings settings;
settings.setValue("HOSTNAME", "localhost");
QTimer::singleShot(10, mainClass, SLOT(run()));
return app.exec();
}
When I fire the app up in the Simulator and open the Settings app, my entry does not appear. Does anyone know how to do this effectively in iOS using Qt?
As it turns out, Qt does provide a way to generate a Settings.bundle file for your app. You need to define a Root.plist and Root.strings file in advance and then add the following to your .PRO file:
SETTINGS_BUNDLE_DATA_ROOT.files += Root.plist
SETTINGS_BUNDLE_DATA_ROOT.path = Settings.bundle
SETTINGS_BUNDLE_DATA_LANG.files += Root.strings
SETTINGS_BUNDLE_DATA_LANG.path = Settings.bundle/en.lproj
QMAKE_BUNDLE_DATA += SETTINGS_BUNDLE_DATA_ROOT SETTINGS_BUNDLE_DATA_LANG
When your project is linked, the bundle will be created.
QSettings is only for storing settings in a persistent fashion. Adding settings to the iOS Settings application is outside of the scope of Qt. Look up "iOS Settings Bundle" for information on how to create those - eg https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/UserDefaults/Preferences/Preferences.html .

Why is the Qt Creator Ubuntu Publish Screen Empty?

I'm trying to publish an app to the Ubuntu Store, however something is wrong with Qt Creator (or something else).
I used to be able to see this:
But now all I see is this:
As you can see (or read, if you're using a Reader with no images), the second image here isn't displaying things like the General tab which allows me to enter details such as Maintainer, Name, Description, Security Policy Groups - it doesn't have a Manifest tab AppArmor tab or Excludes tab either. The Create Package button is gone.
All I am left with is a blank screen with only 1 enabled button which reads 'Validate existing Click package', but when I click that (since there's nothing else I can do, it seems...), it takes me to my Projects directory where all my apps are listed. I select the app in question, and I can't click the open button on the dialog because there is no *.click file anywhere to be seen.
Have I done something wrong? Do you know what's going on here?
Also, I read that in order to publish to the store, we need to create "Click apps". I've searched the universe for this phrase and have come up empty handed. How do I create a "Click app"? I thought the app I was creating was a click app (I went to Qt Creator > Qt Quick Application > ...).
Links:
Tutorial for Publishing apps: http://developer.ubuntu.com/publish/apps/packaging-click-apps/
The reason is that you are using QtCreator from Qt Project proper instead of using the Ubuntu SDK, which delivers its own custom version of QtCreator.
In order to get things done for this, you will need to use the Ubuntu SDK. First you need to install it:
$ sudo add-apt-repository ppa:ubuntu-sdk-team/ppa
$ sudo apt-get update && sudo apt-get install ubuntu-sdk
This will also install the qtcreator-plugin-ubuntu package, its own toolchain, etc. Then you can run it e.g. from the command line as follows:
$ ubuntu-sdk
You can also search in the Unity Dash Applications lens for “Ubuntu SDK” as the image shows below:
You can also just start typing the name in the search line as the images shows below:
Please make sure that you go to the following:
New Project > Ubuntu > Simple UI/Html/QML/etc
rather than e.g. what you tried based on your question:
New Project > Qt Quick Application
You may also with to set up the click targets and device kits part of which (Build and Run) is presented below inline:
First of all you need to read this well , luckily i have been developing ubuntu HTML5 apps recently , so i have been in your place before , you will be able to integrate your c++ code using the QML option ( as ubuntu developers have only 2 options either HTML5 or QML ).
Here is a sample project found on xda to create a simple calculator app ( pay attention how to include your cpp file ):
File Name:apcalc-qml.pro
QT += qml quick
# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
#C++ source files
SOURCES += cpp/main.cpp\
cpp/applicationdata.cpp\
#C++ header files
HEADERS += cpp/applicationdata.h
#Path to the libraries...
INCLUDEPATH += $$PWD\
$$PWD/../../../../usr/lib
DEPENDPATH += $$PWD/../../../../usr/lib
#Path to "other files" in this case the QML-Files
OTHER_FILES += \
qml/main.qml\
qml/basicCalc/*.qml
File Name:main.cpp
#include <QtGui/QGuiApplication>
#include <QGuiApplication>
#include <QQuickView>
#include <QtQml/qqmlcontext.h>
#include <stdio.h>
#include "applicationdata.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQuickView view;
ApplicationData data;
//Resize Mode so the content of the QML file will scale to the window size
view.setResizeMode(QQuickView::SizeRootObjectToView);
//With this we can add the c++ Object to the QML file
view.rootContext()->setContextProperty("applicationData", &data);
//Resolve the relativ path to the absolute path (at runtime)
const QString qmlFilePath= QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), "qml/main.qml");
view.setSource(QUrl::fromLocalFile(qmlFilePath));
//For debugging we print out the location of the qml file
QByteArray ba = qmlFilePath.toLocal8Bit();
const char *str = ba.data();
printf("Qml File:%s\n",str);
//Not sure if this is nessesary, but on mobile devices the app should start in fullscreen mode
#if defined(Q_WS_SIMULATOR) || defined(Q_OS_QNX)
view.showFullScreen();
#else
view.show();
#endif
return app.exec();
}
File Name:main.qml
import QtQuick 2.0
import Ubuntu.Components 0.1
import "basicCalc"
import QtQuick.Window 2.0
MainView {
//objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
applicationName: "apcalc-qml"
automaticOrientation:true;
width: units.gu(60);
height: units.gu(100);
id:root
Tabs {
objectName: "Tabs"
ItemStyle.class: "new-tabs"
anchors.fill: parent
id:mainWindow;
Tab {
objectName: "Calculator"
title: "Calculator"
page:BasicCalc{
width: root.width;
height: root.height-root.header.height;
anchors.top: parent.top;
anchors.topMargin: root.header.height;
onToCalculateChanged: {
//access to the c++ Object
result=applicationData.calculate(toCalculate);
}
}
}
}
}
File Name:applicationdata.h
#ifndef APPLICATIONDATA_H
#define APPLICATIONDATA_H
#include <QObject>
class ApplicationData : public QObject
{
Q_OBJECT
public:
explicit ApplicationData(QObject *parent = 0);
Q_INVOKABLE QString calculate(QString) const;
signals:
public slots:
};
#endif // APPLICATIONDATA_H
File Name:applicationdata.cpp
#include "applicationdata.h"
ApplicationData::ApplicationData(QObject *parent) :
QObject(parent)
{
}
QString ApplicationData::calculate(QString command) const {
// Some Logic comes here
return command;
}
You can check the full tutorial here , though this app is intended to work for ubuntu touch but i believe that all QML projects follow the same procedure.
Publishing App :
First of all click App means a package , a one file click > installs your app AKA (Personal Package Archives (PPA) ) , in order to publish your app , you need to follow some procedure metioned in details here , eventhough the xda tutorial explains everything in a clear way.

Qt5 WebKit not detecting NPAPI plugin

#include "mainwindow.h"
#include <QApplication>
#include <QtWebKit>
#include <QWebView>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWebView *view = new QWebView();
QWebSettings::PluginsEnabled;
view->load(QUrl("http://www.paulirish.com/demo/multi"));
view->show();
return a.exec();
}
I am trying to load a plugin in QtWebkit Webview but it isnt being loaded. I couldnt find the right path as mentioned Here, but it isnt loading. I have added Env. Variable QTWEBKIT_PLUGIN_PATH to System Variable & MOZ_PLUGIN_PATH was already in user variable, added by Foxit Reader. I tried placing the plugin dll file on both the directories corresponding to the Env. Variables but it isnt loading the plugin. After i palced the plugin in Moz_plugin_path, firefox was able to detect the plugin.
As for enabling the plugin in QTWebview i have tried using
QWebSettings::PluginsEnabled;
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled,true);
view->page()->settings()->PluginsEnabled;
but found success with none of them, I am using Windows 8.1 and Qt 5.2
You should set the QWebSettings::PluginsEnabled attribute. The way you are doing it, nothing is happening.
Enable the attribute with the following code:
QWebSettings::globalSettings()->setAttribute(QWebSettings::PluginsEnabled, true);
Put this before your QWebView creation.
Refer to the documentation for more details:
QWebSettings Docs
i have been through exactly the same situation. what solved my problem was to install adobe flash player plugin for NPAPI. Modern web browsers like Google Chrome and Firefox are often distributed with builtin flash player plugin. So Chrome/Firefox works well does not ensure that you have the proper flash plugin installed properly systemwide, which is needed by Qt5WebKit to enable local plugin support for Flash content.
so, make sure the adobe flash player plugin for NPAPI is installed, and hope it would solve your problem.

Qt Creator + OpenCV: Program runs from .exe but not from editor

Well, I need to start working with OpenCV and as I'm used to working with QtCreator, I'm trying to make it all work together. I downloaded the latest OpenCV version, and compiled it with MinGW. Then, I created this little console project to try it out. Below is the .pro file:
QT += core
QT -= gui
TARGET = OpenCV_test4
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\\Librerias\\opencv2.3.1\\release\\include
LIBS += -LC:\\Librerias\\opencv2.3.1\\release\\lib \
-lopencv_core231.dll \
-lopencv_highgui231.dll \
-lopencv_imgproc231.dll \
-lopencv_features2d231.dll \
-lopencv_calib3d231.dll
Here is the main.cpp file:
#include <QtCore/QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// read an image
cv::Mat image= cv::imread("img.jpg");
// create image window named "My Image"
cv::namedWindow("OpenCV Window");
// show the image on window
cv::imshow("OpenCV Window", image);
// wait key for 5000 ms
cv::waitKey(5000);
return a.exec();
}
(I have tried this code with and without the QCoreApplication lines)
The deal is: It links and builds, and when runs from QtCreator only a terminal window called C:\QtSDK\QtCreator\bin\qtcreator_process_stub.exe appears with the line "Press RETURN to close this window..."
But, if I run the .exe from the project folder, it runs perfectly!! Why is QtCreator unable to launch the application? I found this really strange, and I would appreciate any hint about this. It's really not THAT important, but it is kind of a pain to have to run the .exe manually every time I change something to check how it works.
Thanks for your time :)
Additional Info:
I have tried both debug and release versions, the problem is the same in both of them.
Debugging does not work, it never stops at any breakpoint.
I'm running on Windows 7 Proffesional x64
SOLVED, I don't really know what I did, it suddenly worked and keeps working, I wish I could tell you how I fixed it but I have no idea, such a weird thing :(
Check Projects -> Run Settings -> Run in terminal. It have to be enabled, but seems to be disabled.
I have met same problem with QtCreator and OpenCL under Linux. Simple test program works after start from terminal and it does not work after start from the QtCreator.
I found the cause was hardcoded LD_LIBRARY_PATH in the project's run environment settings. I had dropped it to empty string and this had fixed issue.
I had the same issue with the following environment: Raspbian, Qt, openCV and a gui application.
old-ufo recommendation worked for me:
- First, enable "Run in terminal", which failed
- Then, disable "Run in terminal", which allowed me to correctly debug my app.
I understand that this is not scientific.