Deploying Qt QML Compiled Executable - c++

So I have a simple app that uses QML for my graphical interface and c++ code for some of the logic. I was looking for a method to compile the QML into c++ code and link it into my binary and found this page over at the Qt home site:
http://doc.qt.io/QtQuickCompiler/
Basically it says use the resource system for all of my QML graphical interface files and add the QML compiler flag to my qmake config line in my .pro file and everything should be good to go.
As far as I know everything compiles fine, but when I use the the Qt windeployqt.exe tool to get all of the dependency files and test it on a clean system, I get a small white screen as if my QML files were not loaded properly.
I have one c++ reference to my main QML file using "qrc:/mainqml.qml" and that's it.
Any idea what I am doing wrong?

You're using the open source version of Qt. It didn't come with the Qt Quick compiler until Qt 5.11 where it is included - and after a rework, too. So it performs better than precompiled QML did in Qt 5.10 and before.
I get a small white screen as if my QML files were not loaded properly.
... thus you need to deploy these files with the application, otherwise it won't work.
add the QML compiler flag to my qmake config
That flag was a no-op on an open source Qt build until Qt 5.11.

Qt Quick Compiler only shipped with Qt Commercial License, but you can still compile your QML files into qrc file. Starting a Qt Quick application project from Qt Creator does exactly this.
Deploying QML application with windeployqt require additional flag --qmldir, e.g.
windeployqt --(release or debug) --qmldir %PATH_TO_YOUR_QML_FILES% %YOUR_APPLICATION%.exe
It will parse your qml files and deploy all qml imports you used.

Related

Use a QT Widget plugin using static qmake

i have built an QT GUI app using Visual Studio 2017 with Qt VS Tools extension and QT version 5.6 (the one provided by QT precompiled), using Qled widget plugin.
With this Default Dynamic Qt version, the app runs fine with the widget and i have no problems.
But now, i want to build the same app, but static, for use without dependencies.
So, i built QT 5.6 from source with -static parameter, to be more exact i follow this blog's guide. Here problems started to show up:
I tried to rebuild the widget plugin using the static qmake, but i got this error: "Project ERROR: Unknown module(s) in QT: designer"
I tried to use the plugin compiled by the dynamic qmake, and surprisingly, it built with success but the GUI app didn't open at all.
Its worth mentioning that i can use and build a simple default application using a qmake static build.
I think i need to add the Qt Designer Module, but i don't know how to do this, i even tried to rebuild qmake without the "-nomake tools" paramter, but got the same error building the plugin.
just don't build the plugin, you don't need it. Just add the qrc file, and the actual widget *.cpp and *.h file into your project
fix the linkage, delete the QDESIGNER_WIDGET_EXPORT in the *.h file inside your project
This comment managed to solved my problem, thanks to #PeterT

How to debug xcode project in qt?

I want to embed some UI written using Qt and QML via QMacNativeWidget.
And I want to debug QML using Qt Creator, cause I can't debug QML with XCode. Do you know if it's possible?
You can debug Qt/QML in Xcode since it's essentially just a regular C/C++ project. The only thing you need is a proper Xcode project (.xcodeproj).
You could use CMake for project configuration/generation instead of relying on QtCreator's .pro format. With CMake you could switch between IDEs (project generators is the better term) on demand and try things out when it gets OS specific.
If that's not an option (there might be several reasons), you still can generate an Xcode project from an existing .pro solution via qmake in the command line:
qmake -spec macx-xcode project.pro
This can be found in the Qt for macOS section of the docs.

How do I import my makefile project into QtCreator?

I have previously written a large C++ server and client project (containing multiple .cpp's and .h's which run with makefile). Now I want to modify the client to use a graphical user interface.
Should I import all of my codes to Qtcreator and compile them all in the software? How can I implement the makefile then?
Next, how can I modify my client so that the interfaction with the server is controlled from the graphical interface?
Create a Qt project (I guess, you need Qt Widgets application). Copy your existing files into project's directory. Import all these files to your project. Then look what you have to do in main() function. In Qt project it will be in the file main.cpp, and a minimal code for main() will be automatically created by Qt Creator. So, move the necessary code from your main() function there. Then bit by bit look which parts of your code will interact with Qt. Makefile will be created by Qt Creator. Files mainwindow.cpp and mainwindow.h relate to your main window's GUI.
QtCreator supports working with makefile projects. Basically it becomes a glorified text editor and directly invokes make for your project directory. Some features, like compiling a particular file might not work. See this SO question for more details. And then one can manually link/include Qt for your application's GUI.
Project configuration that is natively supported by QtCreator are qmake files. It converts directly into makefiles. This will provide the best QtCreator experience. So another option would be to convert your makefiles into qmake .pro/.pri files. This will require some effort.
I digress, but if you are going to go this way, I can also recommend CMake. QtCreator has on okay (and constantly improving) support for CMake. So do some other IDEs (CLion, VS). And you will always have the option to convert your CMake files into makefiles, Ninja files, VS solution, or even XCode project.

QMediaPlayer, QSound class - unable to #Include files (files are there)

I have been trying to play a simple audio file using:
http://qt-project.org/doc/qt-5/qmediaplayer.html and
http://qt-project.org/doc/qt-5/QSound.html
I am using Qt 5.3 but the problem is, when I type #include QMediaPlayer or QSound, QtCreator keeps underlining them with red because it can't find them. The thing is, the files are there. They are located in QtMultimedia/ and I have seen them. When I try to prefix QtMultimedia/QMediaPlayer or QtMultimedia/qmediaplayer.h it still can't find them.
If I type #include "QtMultimedia/" the auto-complete drop down in the text editor only shows QtMultimedia/QtMultimediaDepends. Normally you get a list of all the files in the folder but not with this one.
Looks like there is something wrong with the paths. How do I fix them? I am using a Windows machine.
Edit: I have included project settings - see screenshots.
I think, after you modified your .pro file, You didn't run the qmake.
build-> run qmake
qmake will generate the makefile you need to build the src code.
if you only change the .pro file, but didn't run it. Nothing is changed.
and that is reason, you create a new project and it is working.
Ok I figured it out. It's a problem with my Qt version.
My Qt 5.3 version is a custom compiled one. When I select the included version that came with the installer, QSound is found. When I change the kit to the custom compiled one, the file cannot be found. I must have forgotten to include some sort of multimedia option to the configure script during compilation.
Now the question is what is the missing option, I will need to do more reading...
Of course, comments and suggestions are welcome :)
You have to add the word 'multimedia' in your .pro file:
QT += core GUI
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets multimedia

QDeclarativeView no such file ot directory. Running QML and c++ application in qtCreator

What I am trying to do is test QML in qtcreator. I have newest version Qt Creator 2.8.1 based on Qt 5.1.1.
I would like to add qml to my c++ application. I tried many ways. The most reasonable look using QDeclarativeView but I can't include it.
in pro files I add
QT += core gui declarative
I tried add quick, qml aswell but then I still don't see qtquick or declarative libraries.
I can see Qt Quick 2 UI project in qmlViewer by go
Tools->external->qtquick->qmlviewer
When I try to build Qt Quick 2 Application(Built-in Types) I get 3x
"Cannot open include file "QtQuick/QQuickView" no such file or directory.
I want to do simple c++ application using qml thanks for any help. I read many tutorials but most of them start after build. I have problem with run application no qml code.
You can't include it, because it's qt quick 1 and you'd like to use qt quick 2. To be able to include QDeclarativeView you need:
QT += declarative
in your .pro file.
Look at QQuickView for the qt quick 2 alternative, for which you need:
QT += qml quick
in your .pro file.