Compiled application don't find QML elements

  • Hi to all.

    I am sadly experiencing a very strange behavior in Qt-Quick when I try to deploy a windows desktop application. I apologize if this post is too long, but I will be sure to descibe exactly what I am doing (including annoying and some obvious operations). I am sure that one or more steps of my proceeding are wrong, but I can't identify them.

    1. The program is finished and works correctly, when I compile under Qt IDE and run the release.

    2. Settings for project folders are the following:

    | +--MyAppFolderName
    | +--main.qml
    | +--elements
    | +[All Qml Sources.qml]

    Then I compile the application for the desktop, with shadowbuilder option active. At this point I obtain a build dir for the desktop as follows:

    | +--qml
    | +--MyAppFolderName
    | +--main.qml
    | +--elements
    | +--[All Qml Sources.qml]
    | +--[All Other Files (images etc.)]

    With this folder tree (created by Qt IDE) the application report the error not found for the qml source main.qml, so I need to remove the second 'qml' folder. Then after this manual operation the application runs under the Qt IDE.

    At this point, to see the application working out of the Qt IDE I need libraries and plugins. Thus with DependencyViewer I search what are the missing DLL and add the corresponding plugins, so the build-desktop folder became as follows:

    | +--MyAppFolderName
    | +--main.qml
    | +--elements
    | +--[All Qml Sources.qml]
    | +--[All Other Files (images etc.)]
    | +--[A different folder for every plugin]
    +--[All the DLL needed to run the application]

    Note: In the project file I set the following folder to be included in the deployment path:

    @folder_01.source = qml = qml
    DEPLOYMENTFOLDERS = folder_01@

    while in the main.cpp source I setup the plugin path:

    @int main(int argc, char *argv[])
    QApplication app(argc, argv);

    // Creation of the viewer instance
    QmlApplicationViewer viewer;
    // set the qml starting program
    return app.exec();


    When I launch MyAppProgram.exe the application starts, but seems that no Qml file or object is loaded. I suppose that this is the build directory, while the final deploy directory is different. How can I setup correctly the path to have the application working correctly?

    Thank to all for any suggestion.

  • Your QML files also need to be in the correct path from the actual .exe file. Otherwise, the exe won't be able to find them. Line 11 of the code snippet above tells you where that would be. Note that that is where you are using a relative path.

    So, you either need to copy them to the dir your app is build in (or deployed to), use an absolute path, or you need to start thinking about using the Qt resource system. That will allow you to add all your qml (and image) files in one or more resources, and build them right into your application. In that way, you don't need to distribute them separately anymore. You would only need to modify the reference in line 11 above to point to your resource, and Qt does the rest.

  • Thank you Andre!

    I already set the qml dir in the relative path as described in line 11 of the snipped (I tried in a lot of way :( ) but it still doesn't work.
    The use of Qt resource system (I need to document on it) semms the most effordable and robust way. But in this moment I have the need and I continue to have not clear the right application treee.

    The last try I have done, is set so in the exe dir (i.e. MyAppRelease)
    there is a folder tree like qml/qml/MyApp.qml and the relative components subdirectory. As you suggest. But it don't work anyway.

    Is it possible that this problem depends by the path management that is with the slash (linux based) while windows needs the backslash?

  • No, Qt will accept forward slashes on all platforms. It is recommended practice to use forward slashes everywhere, and only change convert to/from the native encoding for user-visible representations.

    Edit: QDir supplies the methods for that encoding and decoding to native separators.

  • Thank you, but this was not the problem. I just tested now.

    Then I seta qrc file with the images, qml and html paths in three different sections. I am trying to see if this method works.

  • Well, I have done some tests and the conclusion is that something is wrong or something is lost or something need to be changed.

    The behavior described above is strange, and the tests and changes done are very simple and obvious: the paths a right and correct, as the documentation explain.

    now following your suggesions - Andre - I setup a wrc file with all the resources listed. It is ver simple, withouth any other than the list of the qml files and images. The paths are impossible to be wrong because I used the IDE where file should be searched with a dialog box.
    Then, I changed the only in two lines: Q_INIT_RESOURCE call to initialize the resources in the resources.qrc file and in the call to qml main program.

    @#include <QtGui/QApplication>
    #include <QCoreApplication>
    #include "qmlapplicationviewer.h"

    int main(int argc, char *argv[])
    QApplication app(argc, argv);

    app.setApplicationName("RC Hobby Stream by ");
    app.setApplicationVersion("1.0rc LGPL 3.0 lic. by Tech Consulting,");
    app.setOrganizationName("Maplegate Media Group");
    // Creation of the viewer instance
    QmlApplicationViewer viewer;
    // Modifications to remove window attributes
    // set the qml starting program
    return app.exec();


    Well, recompiled in debug without any warning or error. When the program starts the object viewer really contains the string name but starting I receive the error that the main.qml file is not found.

    The very strange thing (or what I don't expect) is that the not found file is the following line:

    @file:///E:/QTDevel/RCHobbyStream-build-desktop/:/main.qml: File not found@

    This seems to me something of bad path, just as Qt resource system is not working correctly.
    Thus, to complete all the possible tests I thought, I pushed the git repo from the windows machine to the public repository (hosted at then taken the same project in the Mac environment. Started the Qt Creator and opened the project, leaving all unchanged. The result is about the same, with the project locally stored in the path ~/QTDevel/rchobbystream:

    @file:///Users/enrico/QTDevel/RCHobbyStream-build-desktop/ File not found @

    I have no more idea. Some suggestions ?

  • Other tests done.

    Using Qt resource system nothing works, also under the Qt Creator IDE. The error is always the same, main.qml could not be find.
    Then, reusing the relative paths with the sources under the 'qml' folder the program work and compile correctly but if I run it standalone does not find the file the is surely in the folder where the program expects.

  • You are doing something wrong, as I use this setup in a project, and I know for a fact that works :-)

  • Andre I am sure that I am doing something wrong. And probably it is a so stupid thing that I can't imagine.

    All the work was done on the drive E: and now I am moving the project on the drive C: (standard windows), the same where the SDK is installed.

    Its possible that I missed something ?

  • Are you sure you are not using an absolute path somewhere?

  • Yes, Andre, absolutely sure. But at this moment it doesn't matter, because the first step is to see that program running in the compiled version at leat with main working. In previous versions, there was not plugins, so something wasn't working like the jpeg files but it starts and show a blank window of the wrong size. Not only can't be there an absolute path because in the Qt IDE everything works also when I move from one drive to another.

    There are two things that I am not sure what means:

    1. in the project I set these lines on top, because I found this in all the examples and other projects but is possible that I have not understood clearly what does it means.

    @# Add more folders to ship with the application, here
    folder_01.source = qml = qml
    DEPLOYMENTFOLDERS = folder_01@

    1. When I compile, with the settings explained above, Qt create the folder Rc_Hobby_Stream_build_desktop that contains the following subfolders:

    qml/qml/elements/qml files
    release/the compiled exe
    debug/the compiled exe

    The strange thing is that I don'set in the project (and in the main.cpp program) this double qml/qml folder tree, there is only one folder.
    When I run the program from the Qt IDE, I receive the error main.qml not found, because the program search it in the right directory: Rc_Hobby_Stream_build_desktop/qml/main.qml

    Well, I remove the redundant /qml/ folder and all works fine. Thisi last thing is what that suggest to me that something is wrong.

  • Finally I found the problem!!!

    Last night after another set of annoying tests and controls, I focused where is exactly the problem. Unfortunately this doesn't mean that it is solved, but now I can investigate on the error (??? if it is) seeing in the right direction.

    Note: to develop I am using the Qt SDK 1.1 beta, but as I explain further it doesn't matter.

    The fact that QML components are working in the IDE while don't work running the program stand-alone suggested to start a line of investigation on main.cpp calling main.qml, and Andre got a lot of helpful hints to check the correct path, see if the QML components were in the right place, if all the dll and plugins were copied etc. Then I have also investigated on the main.cpp code structure.

    During my tests I experienced the same problem on linux Ubuntu 10.4LT, Mac OSX 10.5 Snow Leopard, Windows 7 Perfection SP1, Windows XP professional SP2...

    At this point a thing was clear: the cpp components of the application was correct. So where is the problem?

    1. I created a fresh virtual Windows 7 machine and installed the Qt Creator and Qt SDK 1.0, to have the same development environment as described by Andre some posts above in this thread. The result was the same, so I excluded that in my development configuration with the new SDK 1.1 beta something was wrong.

    2. I left unchanged the C sources and structure and changing only the QML sources, using an old version, the 1.0.3 beta of the same application. Astonished last night at 3 A.M. I saw that all was working!!!

    At the actual date I am debugging the QML sources, but the thing very strange for me concerns the real question, at this point:

    What can be that QML code works only when the program run inside the Qt-Quick IDE, while it shows a blank screen when is run stand-alone (in a separate folder, with the dll and plugins?)

    If someone has any idea is welcome :)

  • Are you sure you also distribute all the needed libraries that you reference (indirectly) from your QML, and that may be in the path when you run from Qt Creator? I am thinking about things like the QtMobility related libraries...

  • Hi Andre, you think good :)

    Plugins was correctly delivered, and all the libraries evidentiated by dependecy walker, but it was not sufficient because there was a couple of dll that needed to be added.

    When I checked (this will be in next post) and verified that also the qml was working, I tried to do the oppposite as adding the dll. Added all and removed what I was reasonably sure that are sensless.
    And now it works.

    Remain only the qml debugger that I setup correctly, but when the debugger starts, tell me that the debugger can't connect with the server. This can depend by some piece of code I should add in the source? I only setup all that the guide ask for, but the code remain unchanged.

  • Situation change and update

    Atthe actual date, this strange problem has not yet finished to astonish...

    The installation directory is working with all the needed dll. While the aplication is in the same computer where is also installed Qt SDK. Then, I tried to move in a "empty" windows machine and the application show the same simpthoms explained before.

    So I do the following test: all the dll under .../desktop/mingw/bin was copied in the application directory, while all the plugin dll was copied in subdirectories under the /plugin application directory.

    In this condition, the application directory contains all needed and not needed components (it is about 65 Mb). When I copy the application directory in a windows machine where the Qt sdk is not installed, the application starts with a blank screen.

    No more ideas to test :)

  • Old thread but thought I'd post my solution: had a bit of the same problem. I was able to sort out all needed dependencies by:

    • Using resources for qml files
    • Using dependencywalker to find missing dlls in the main exe file, copying them into the exe folder
    • Starting from a dummy main.qml that paints a red rectangle. One by one I added the qml imports in main.qml, compiled and then ran the standalone app. If it did not run there was a problem with the imported plugin -> fix it: add the plugin in a QtQuick folder in the directory of the exe + use dependencywalker to check if all the required dlls are present

    Its a bit tedious but with this step-wise approach you're sure to sort it out.

    edit: never mind, ended up following the instructions "here":

  • @Alicemirror
    Though too late reply yet worth posting.
    If qrc is not used then Absolute path of qml file
    "/home/manoj/QT/qmlFileDemo/main.qml" can solve the problem.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.