QMLComponent not ready in deployed app - qt

I'm using Qt 5.5 to create a small app. In the app, I'm manually creating a component like so:
QQmlComponent component(engine, QUrl("qrc:/Box.qml"));
assert(component.isReady());
My .qrc file IS included in the .pro file like so:
RESOURCES += qml.qrc
All works well when I run from Qt creator. However, when I deploy the app using the macdeployqt tool and try to run the app I get that assert hit. Sure enough, I tried to put a loop around the .isReady() and it will hang forever.
What is the proper way for doing this? My qml component is working fine when in the Qt creator, so why does it fail in deployment?
Thanks

This turned out to be simple. You need to pass -qmldir=<path to your qml files> to macdeployqt. It is actually required if you have QML files but I somehow didn't see it in the documentation.

Related

Qt error with reMarkable tablet app

I have a reMarkable tablet , which I mostly love except for the lack of linux support (surprising given it is a linux-based OS). However, I've managed to find a version of a linux application that is now unofficial. This github is actually a Qt docker app, but if you look in the code for the 'Dockerfile' you can find where to download the app, which is apparently still on the server even though there's not a link from the main web page. Anyway, I downloaded it and got it mostly working, figuring out a few dependencies based on same Dockerfile code. But, I can't seem to get file dialogs to work, which is the main reason for using the app.
The error I get is:
ERROR: No native FileDialog implementation available.
Qt Labs Platform requires Qt Widgets on this setup.
Add 'QT += widgets' to .pro and create QApplication in main().
I'm not a Qt developer, so I'm lost. I'd love to get this to work. Thanks.
In the .pro file of you project you should add this line QT += widgets
or just add widgets to the line with QT += ...
Qt can use native file dialogs on some platforms, and will fall back to its own implementation if none is available. But that requires that the application is built including the QtWidgets module, and using a QApplication.
If you don't have the source code of the app and a possiblity to rebuild it, there's no chance to fix this from a binary

Qt Creator and QML Live Preview

The problem now is that I don't know how I can use qml live preview?
I saw a video:
https://vimeo.com/145921618
I saw this post about erase this function for Qt Creator.
How i can implementlive coding into my app?
Perhaps you mean Terrarium?
Terrarium is a cross platform QML Playground: the view renders lively
as you type in the editor, makes prototyping and experimenting with
QtQuick a lot more fun!
It monitors changes in its TextEdit, and triggers the view to reload
source from the local http server. If you're looking for a file system
watcher implementation, please refer to QML LiveReload.
Or LiveReload?
As is evident from the video, this is as simple as auto reloading a QML file each time a chance to the file has been saved.
You can easily do that yourself, set up a QFileSystemWatcher and every time the file is modified, load the file in a QML view. And there you have it.
Of course, this is only good for previewing standalone components which can work on their own. You could go further, set the file system watcher to monitor the entire QML project and reload the main QML file every time something changes. It is a two step process, you need to monitor the directory, which only reflects adding or removing of files, and you subsequently add or remove those files from watching for changes.
Just for the sake of it, I want to share another tool that I found online.
It is a web based QML editor that gives immediate preview while writing the code. It has its limits, but still it's pretty useful for live QML coding
https://qmlweb.github.io/
If someone is still interested, in my Qt 5.10 installation, there is a qmlscene.exe in bin folder (same location as qmake or assistant). Running on command line is fine, however it is not in Qt creator.
PS: I found this:
http://doc.qt.io/qt-5/qtquick-qmlscene.html

Getting an all-white screen on deploying Qt Quick demo app Minehunt

To test the deployment process I am trying to deploy the included demo app Minehunt. I am able to get it to run, no crashing or errors, but the screen is all white.
I believe this generally means that I am missing plugins. Dependency walker reports no problems, and I even tried including ALL the plugins from the Qt MingW plugins directory, but no such luck.
Here is what I am including so far; Can anyone advise what else I need to add to get it to run?
Your dlls don't look bad at all. I think, too, that it's your plugins. Even if they are there, there is a good chance, that your program don't find them. Qt is a bit picky where to look by default. You might try qt.conf. This is a small textfile you must create in the folder where your executable lies. It contains the path to your Qt plugins.
For instance, in one of my projects I have the followin folder layout:
Appfolder
plugin
qt
plugins
imageformats
sqldrivers
myapp.exe
qt.conf
...many dlls...
Then I added a qt.conf file to the Appfolder, which has the following content:
[Paths]
Plugins = plugins/qt/plugins
My program is Qt 4, but I don't think this aspect of plugin deployment changed in Qt5.
All my qt dlls are in qt. And I add the following PATH: SET PATH=.\plugins;.\plugins\qt;%PATH%. Works like a charm on any Windows I ever tried.
Edit:
I then created a .bat file, which does:
SET PATH=.\plugins;.\plugins\qt;%PATH%
cd Appfolder
start myapp
This was an ugly quick fix, which I did not have the time to replace with something better, yet.
If application runs and shows blank screen then that usually indicates two things :
All the dependencies (dlls) are probably present and detected properly.
Most probably whats missing is the presence of qml files at the correct location.
In your main.cpp check the path of qml file which you would have given, and see if relatively that folder is present at the same location corresponding to your executable.
Also, instead of running the executable by double clicking, run it through the command line. It might print some messages if it is not able to locate some images/files/other dependencies etc according to the specified paths.
Edit 1 :
Add this flag in the .pro file :
CONFIG += console
It will give the exact debug message in a console once you run the application.

Problems with QT 5 deployment

I've attempted to follow the instructions on deploying Qt to Windows, but I am stuck on step number 1. In it, it tells you to:
cd C:\path\to\Qt
configure -static any other options you need
Unfortunately, I can't get the Qt DOS prompt to recognize the "configure" command despite attempting to use it in virtually every folder under my Qt installation. Does anyone know where this command is store? Everything else about my project is working great with Visual Studio, but I just can't seem to figure out the deployment.
I've Googled the crap out of this and tried both the Qt and the regular Windows command prompts. Any help would be greatly appreciated!
Thanks
EDIT: For clarity, I have tried dragging all of the .dlls needed to run my program (by running it and finding the ones I get errors on), but all that happens is I stop getting errors when trying to run my app. If I double click it with the .dlls in the same folder, nothing happens at all.
Are you sure you need the static Qt build? Note that you must static build the actual Qt framework for that, and only after that you can build your application.
If yes, make sure you have the Qt source code, because configure is part of the source code of Qt, it's a tool that configure the Qt build.
The step refers to path of Qt Source directory e.g. C:\QtSDK\QtSources\\
As you can see in qt5 source tree there is a file configure.bat
You need to run that with static option, so it will configure Qt for static linking.
Then you need to re-build Qt to make your new configuration to take effect.

C++ Qt - QPixmap does not load with Qt Creator, but load when run via terminal

I am coding a GUI using Qt. When I run the application using QtCreator, my images do not load, and I receive the following error:
QPixmap::scaled: Pixmap is a null pixmap
Yet, when I run the application via command line, everything displays perfectly.
Why so? And how can I get QtCreator to load my images properly?
NB: Those images are barely 20ko each, so what I read about images being too big can't apply.
EDIT: A typical filename is 'Images/Cards/Base/card01.jpg', where Images is a subdirectory of my project directory (the code being at the root)
If you are working with images that should be bundled with the application, such as icons, then you should try and make use of the Qt Resource system.
This allows you to build the resources into the actual project and reference them in a filesystem independent syntax. i.e.: :/icons/myIcon.png
Most likely you have a difference between the relative location of the file in Qt Creator vs the command line.

Resources