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