Add Settings entry for iOS app using Qt 5.4 - c++

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 .

Related

Qt WebEngineView: Problem with loading a WebGL project (exported from Unity)

I'm trying to download a WebGL project (exported from Unity 2018.3.14f1) in Qt WebEngineView (Qt 5.12.0)
For an example, WebGL project was created in Unity 2018 - an empty scene without objects (camera only) - Screenshot: Unity project
and exported to the WebGL Assembly (applied .gzip compression, build size 2.3 MB) - Screenshot: Unity build settings
The Qt project was take from Qt's library of examples ("WebEngine Widgets Minimal Example").
#include <QApplication>
#include <QWebEngineView>
QUrl commandLineUrlArgument()
{
const QStringList args = QCoreApplication::arguments();
for (const QString &arg : args.mid(1)) {
if (!arg.startsWith(QLatin1Char('-')))
return QUrl::fromUserInput(arg);
}
return QUrl(QStringLiteral("file:///F:/qt/test4Exp/index.html"));
}
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
QWebEngineView view;
view.setUrl(commandLineUrlArgument());
view.resize(1024, 750);
view.show();
return app.exec();
}
When you open a WebGL project in Chrome, everything loads very quickly (instantly) - Screenshot: WebGL project opened in Chrome
When you open WebGL in WebEngineView, the project takes a very long time to load (about 5-6 minutes) - Screenshot: WebGL project loading in WebEngineView
... but then it opens - Screenshot: WebGL project loaded in WebEngineView
The WebGL project is opened from a local drive. I have tried various options for Unity export parameters (brodil compression, code optimization, etc.). Tell me, what could be the problem? Can be applied to any option in the Assembly or in QCoreApplication::setAttribute ?
Below attached the project WebGL and Qt project
WebGL Project
Qt Project
The problem was solved after running the application from under exe file (not from under QtCreator).Everything works faster under exe file. Apparently the launch and initialization of the Unity engine is slowed down by QtCreator. When the application is running under exe web project launch in Web Engine View takes 2-3 seconds (on an old PC 7-9 seconds).

Invisible text in QTextEdit

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.

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.

Compiler can't find ui_xyz.h file

I've install Netbeans 7.2 and Qt 5 on Windows7. Everything compiles fine.
But recently when I create a Qt form and try to use it in this way:
New Project > C/C++ Qt Application > Finish
Right click on new Qt project > New > Qt Form > Finish
After saving ui file in Designer
This error appears:
newForm.h:11:24: fatal error: ui_newForm.h: No such file or directory
The content of main.cpp is :
#include <QGuiApplication>
#include "newForm.h"
int main(int argc, char *argv[])
{
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);
QGuiApplication app(argc, argv);
// create and show your widgets here
return app.exec();
}
I tried to manually create ui_xwz.h file and add it to my project. But I want it work automatically as same as before. How can I solve it?
I have a ridiculous solution, Maybe we should report it as a bug to Netbeans or Qt.
Go and active QtSVG and QtXml modules of your project and rebuild it. I tested this way and the problem vanished.