Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [this one sucks] Application works only in specific folder, exits silently in another folder
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Installation and Deployment
31 Posts 5 Posters 15.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hedge
    wrote on last edited by
    #5

    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@

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Peppy
      wrote on last edited by
      #6

      is there that file??

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hedge
        wrote on last edited by
        #7

        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.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Peppy
          wrote on last edited by
          #8

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

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hedge
            wrote on last edited by
            #9

            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.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #10

              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...

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hedge
                wrote on last edited by
                #11

                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.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #12

                  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.

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    Hedge
                    wrote on last edited by
                    #13

                    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.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #14

                      Who ever told you to use that QUrl?

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        Hedge
                        wrote on last edited by
                        #15

                        setSource requires a QUrl.

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          Peppy
                          wrote on last edited by
                          #16

                          QString is so beautiful class, isn't it?

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #17

                            [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]

                            1 Reply Last reply
                            0
                            • H Offline
                              H Offline
                              Hedge
                              wrote on last edited by
                              #18

                              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 @

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andre
                                wrote on last edited by
                                #19

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

                                1 Reply Last reply
                                0
                                • H Offline
                                  H Offline
                                  Hedge
                                  wrote on last edited by
                                  #20

                                  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>
                                  @

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    giesbert
                                    wrote on last edited by
                                    #21

                                    Hi Hedge,

                                    this

                                    @
                                    <qresource prefix="/">
                                    @

                                    is not needed, it could be

                                    @
                                    <qresource prefix="">
                                    @

                                    Nokia Certified Qt Specialist.
                                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                    1 Reply Last reply
                                    0
                                    • H Offline
                                      H Offline
                                      Hedge
                                      wrote on last edited by
                                      #22

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

                                      1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        goetz
                                        wrote on last edited by
                                        #23

                                        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.

                                        http://www.catb.org/~esr/faqs/smart-questions.html

                                        1 Reply Last reply
                                        0
                                        • H Offline
                                          H Offline
                                          Hedge
                                          wrote on last edited by
                                          #24

                                          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).

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved