[this one sucks] Application works only in specific folder, exits silently in another folder



  • Project description:

    My qml-desktop-applications uses the "Qt Quick components for Desktop":http://labs.qt.nokia.com/2011/03/10/qml-components-for-desktop/.

    I compile all files from the desktop-components into a resource-file (which is embedded in the .exe-file).
    The main.qml-file is loaded from the resources like this:

    @viewer.setSource(QUrl("qrc:/main.qml"));@

    main.qml starts with this line which seems to make trouble:

    @import "desktop-components/components"@

    Observed behaviour:

    • When I compile and execute the application everything works fine
    • When I move my application to another directory (or PC), the application's main window never shows up.
    • When I remove all desktop-components stuff and just define a simple Rectangle in main.qml it works.
    • When I load the qml-file (and therefore the desktop-components from the file-system instead of the resource-file it works (viewer.setSource(QUrl("main.qml"));
    • The problem doesn't occur on OSX

    Project file-structure:

    @MyProject
    |- release
    | |- MyProject.exe
    |
    |- desktop-components
    | |- components
    |
    |- main.qml
    |
    |- qmlapplicationviewer@



  • You have weird problems, Hedge :-O

    What it should to do before it ends?



  • Show a window.



  • Is everything okay, no warnings?

    Give me code what are you doing before showing the window...



  • By setting message-boxes I could determine that the problem occurs at this line:

    @viewer.setSource(QUrl("qrc:/qml/TraktorScrobbler/main.qml"));@

    In the project-file I include the qrc-file into the executable:

    @# Compile Resources in Binary
    RESOURCES +=
    resources.qrc@



  • is there that file??



  • yeah it's built and compiled inside the .exe.

    EDIT: I tested it in debug-mode. It works in it. Now I have to find out what's the difference between the builds.



  • I don't work with QML but I would like to see more of your code before you start rendering your window...



  • The main.qml looks like this:

    @import QtQuick 1.0
    import "../../desktop-components/components"

    Button {
    }
    @

    When I replaced it with:

    @import QtQuick 1.0

    Rectangle {
    color: "blue"
    }
    @

    It worked. I could execute the application and show the blue rectangle, so there must be something wrong with the desktop-components or styleplugin.dll which it needs.



  • Hi Hedge,

    I think, the bug is

    @
    import "../../desktop-components/components"
    @

    you tell it to go two dirs up and then to desktop-components/components.
    If you put everything into the resource, you should reference the resources, otherwise use the relative path from the executable to that folder...



  • Hello Gerolf,

    I did some further testing with your suggestion (changed the file structure).

    It is now like:

    @MyProject
    |- release
    | |- MyProject.exe <- this is the one I execute
    |
    |- libs
    | |- kqoauth
    |
    |- desktop-components
    | |- components
    |
    |- main.qml
    |
    |- qmlapplicationviewer@

    I also adjusted the import-path in the qml-file to import "desktop-components/components".

    My funny find is that it works if I don't use the Qt-resource system:

    @viewer.setSource(QUrl("main.qml"));@

    As soon as I switch to QMLs resource-system again (QURL("qrc:/main.qml")) the executable hangs as before.



  • You seem to misunderstand the Qt resource system. You don't need QUrl to work with it. You work with it by using a specially constructed file path, that starts with ":/". Depending on the structure you have applied in your resource file, your file name for the viewer should then be something like ":/main.qml" or ":/qml/main.qml". If you keep all in-qml file names (such as for images and other QML files) relative, you don't need to explicitly reference that a file comes from the resource system anymore.



  • So you mean when I set the source like this:

    @viewer.setSource(QUrl("qrc:/main.qml"));@

    an

    @import "desktop-components/components"@

    in main.qml will work?

    If that's right then something else must be wrong since that is causing the trouble.



  • Who ever told you to use that QUrl?



  • setSource requires a QUrl.



  • QString is so beautiful class, isn't it?



  • [quote author="Hedge" date="1305721995"]setSource requires a QUrl.[/quote]

    Sorry, you are right. But you did not read the docs quite well either:

    [quote]Ensure that the URL provided is full and correct, in particular, use QUrl::fromLocalFile() when loading a file from the local filesystem.[/quote]



  • Sorry, that I didn't mention this earlier but that is a problem since my qrc-file is compiled into the executable-file by this entry in the .pro-file:

    @# Compile Resources in Binary
    RESOURCES +=
    resources.qrc@

    So
    @viewer.setSource(QUrl::fromLocalFile(":/main.qml"));@

    doesn't work in this case, because it seems to look for a real file.

    The error is

    @file:///D:/MyProject/:/main.qml: File not found @



  • Could you show us the contents of your resources.qrc file?



  • Yeah, no problem.

    @<RCC>
    <qresource prefix="/">
    <file>main.qml</file>
    <file>images/haken_gruen.gif</file>
    <file>images/connected.png</file>
    <file>images/not-connected.png</file>
    <file>desktop-components/components/plugin/libstyleplugin.a</file>
    <file>desktop-components/components/Button.qml</file>
    <file>desktop-components/components/ButtonRow.qml</file>
    <file>desktop-components/components/CheckBox.qml</file>
    <file>desktop-components/components/ChoiceList.qml</file>
    <file>desktop-components/components/components.pro</file>
    <file>desktop-components/components/ContextMenu.qml</file>
    <file>desktop-components/components/Dial.qml</file>
    <file>desktop-components/components/Frame.qml</file>
    <file>desktop-components/components/GroupBox.qml</file>
    <file>desktop-components/components/Makefile</file>
    <file>desktop-components/components/ProgressBar.qml</file>
    <file>desktop-components/components/qmldir</file>
    <file>desktop-components/components/RadioButton.qml</file>
    <file>desktop-components/components/ScrollArea.qml</file>
    <file>desktop-components/components/ScrollBar.qml</file>
    <file>desktop-components/components/Slider.qml</file>
    <file>desktop-components/components/SpinBox.qml</file>
    <file>desktop-components/components/Switch.qml</file>
    <file>desktop-components/components/Tab.qml</file>
    <file>desktop-components/components/TabBar.qml</file>
    <file>desktop-components/components/TabFrame.qml</file>
    <file>desktop-components/components/TableView.qml</file>
    <file>desktop-components/components/TextArea.qml</file>
    <file>desktop-components/components/TextField.qml</file>
    <file>desktop-components/components/ToolBar.qml</file>
    <file>desktop-components/components/ToolButton.qml</file>
    <file>desktop-components/components/custom/BasicButton.qml</file>
    <file>desktop-components/components/custom/Button.qml</file>
    <file>desktop-components/components/custom/ButtonColumn.qml</file>
    <file>desktop-components/components/custom/ButtonGroup.js</file>
    <file>desktop-components/components/custom/ButtonRow.qml</file>
    <file>desktop-components/components/custom/CheckBox.qml</file>
    <file>desktop-components/components/custom/ChoiceList.qml</file>
    <file>desktop-components/components/custom/components.pro</file>
    <file>desktop-components/components/custom/GroupBox.qml</file>
    <file>desktop-components/components/custom/ProgressBar.qml</file>
    <file>desktop-components/components/custom/qmldir</file>
    <file>desktop-components/components/custom/Slider.qml</file>
    <file>desktop-components/components/custom/SpinBox.qml</file>
    <file>desktop-components/components/custom/TextField.qml</file>
    <file>desktop-components/components/custom/behaviors/ButtonBehavior.qml</file>
    <file>desktop-components/components/custom/behaviors/ModalPopupBehavior.qml</file>
    <file>desktop-components/components/custom/private/ChoiceListPopup.qml</file>
    </qresource>
    </RCC>
    @



  • Hi Hedge,

    this

    @
    <qresource prefix="/">
    @

    is not needed, it could be

    @
    <qresource prefix="">
    @



  • Thanks for the suggestion. That doesn't fix the problem though.
    Do you have other suggestions?



  • This works for me:

    ------ main.cpp ------
    @

    #include <QtGui/QApplication>
    #include <QDeclarativeView>

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

    QDeclarativeView view;
    view.setSource(QUrl("qrc:/qml/QMLwithResource/main.qml"));
    view.show();-
    
    return app.exec();
    

    }
    @

    ------ qmlresource.qrc ------
    @
    <RCC>
    <qresource prefix="/">
    <file>qml/QMLwithResource/main.qml</file>
    </qresource>
    </RCC>
    @

    Watch out if you use the autogenerated qmlapplicationviewer, it has a setMainQmlFile which takes a QString as argument. On the Mac the path is adjusted to look into the AppBundle.app/Contents/Resources directory. You might want to adjust that class to take a QUrl as argument.



  • Hello Volker. The problem must be the:

    @import "desktop-components/components"@

    inside the main.qml file. It works without it (I replaced the whole GUI with just a rectangle).



  • It works for me too (all in resources, no access to files on the disk):

    @
    <RCC>
    <qresource prefix="/">
    <file>qml/QMLwithResource/main.qml</file>
    <file>qml/QMLwithResource/parts/FancyText.qml</file>
    </qresource>
    </RCC>
    @

    In main.qml I have :

    @
    import QtQuick 1.0
    import "parts"

    Rectangle {
    width: 360
    height: 360
    Text {
    id: ttt
    text: "Hello World"
    anchors.centerIn: parent
    }
    Text {
    id: blurb
    text: "blurb"
    anchors.top: ttt.bottom
    anchors.horizontalCenter: parent.horizontalCenter
    }
    FancyText {
    id: ft
    anchors.top: blurb.bottom
    anchors.horizontalCenter: parent.horizontalCenter
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
    

    }
    @

    FancyText.qml is

    @
    import QtQuick 1.0

    Item {
    id: fancyTextId
    width: 100
    height: 62
    Text {
    id: fancytextid
    text: "This is a fancy text"
    }
    }
    @

    You can add this snippet to your main.cpp, at the beginning. It shows you in which paths the qml files are searched for:

    @
    QByteArray data = "1";
    qputenv("QML_IMPORT_TRACE", data);
    @



  • @ QByteArray data = "1";
    qputenv("QML_IMPORT_TRACE", data);
    qDebug() << data;@

    Output is "1" still.

    You've spend so much time with my project.
    I hope I can make it to the Qt Summit and spend a beer.

    Now that you already have a test-setup why don't you try the desktop-components http://qt.gitorious.org/qt-components/desktop (release-build + move exe to another folder).

    I smell there's some bullshit going on there because when I run the release-build exe through Qt's debugger there occurs an error within styleplugin.dll .



  • bump New day, new ideas?



  • Sorry, I was too busy today. I didn't forget your issue - stay tuned :)



  • This wasn't specifically referring to you.

    I'm tuning the OSX-version in the meantime.
    Oh btw. I don't have this problem on OSX. I can put the app anywhere and it works fine.



  • Ok I did another try.
    This time I added ALL files of desktop-components to the qrc-file (even the dll which isn't supposed to be there) but still no luck.

    It's clearly the line import "desktop-components/components" in main.qml which make the application crash.



  • DLLs cannot be loaded from qrc files anyways - it will just bloat the exe. I still need my MinGW environment to check on a Windows box :)


Log in to reply
 

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