PDA

View Full Version : how to convert qml to exe?



hashb
21st September 2010, 04:02
Hi All,

I write a simple qml file, I can use it whith qmlviewer,but how can I compile it
to a executable binary file?


Thanks advance for your help!

Best regards,
hb

wysota
23rd September 2010, 00:49
Create a view for your file, wrap it all into main() and run it.

int main(int argc, char **argv){
QApplication app(argc, argv);
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("myqmlfile.qml"));
view.show();
return app.exec();
}

fervenceslau
6th November 2010, 21:03
I dont know why, but that isnt working for me...
when I run the exe file I get the following messages:

"Qwidget: Must construct a QApplication before a QPaintDevice

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information."

and the .exe file stopped working...

any ideas?

wysota
6th November 2010, 21:14
The idea is your code is different than mine. You have some global object that is a paint device and that's forbidden.

fervenceslau
6th November 2010, 21:21
Damn this qt things are too complicated! (for begginers of course (like me)).
The code im trying to compile is this:

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

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

QDeclarativeView *view = new QDeclarativeView();
view->setSource(QUrl::fromLocalFile("main.qml"));
view->show();

return app.exec();
}

and I have the main.qml that is one of the tutorial's guide:

import Qt 4.7

Rectangle {
width: 300
height: 300

color: backgroundColor

Text {
anchors.centerIn: parent
text: "Hello Yellow World!"
}
}

and the error occurs. And its not because of the view pointer...
I first tried your way and then copied this code from qt's tutorial guides...

wysota
6th November 2010, 21:25
Is this really the whole code you have?

fervenceslau
6th November 2010, 21:33
yup. And my qt version is 4.7.0 ...

wysota
6th November 2010, 21:48
This code is correct and it works for me. Check your project file for any additional files you might have there.

fervenceslau
6th November 2010, 21:53
#-------------------------------------------------
#
# Project created by QtCreator 2010-11-06T17:38:54
#
#-------------------------------------------------

QT += core

QT -= gui

TARGET = Teste
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app

SOURCES += main.cpp

LIBS += -lQtDeclaratived4


=/

wysota
6th November 2010, 21:56
What if you remove the LIBS line and add this instead (I doubt it will change anything but will be more correct anyway):
QT+=declarative

Oh, I see what's wrong. You have a "QT-=gui" line, remove it. Your code shouldn't even build with it there, you must have moved your includes to some weird place so that the compiler can see them.

The project file should look like this:
TARGET=Teste
SOURCES += main.cpp
QT += declarative
CONFIG += app_bundle

fervenceslau
6th November 2010, 22:48
Same problem even altering the .pro file...

Whats the procedure to compile with QtCreator?
Maybe im doing something wrong?

Added after 34 minutes:

Funny... I pressed the 'run qmake' thing and now when I try to compile i get these errors:

c:\Qt\2010.05\qt\lib/libqtmaind.a(qtmain_win.o):: In function `WinMain@16':
C:\qt-greenhouse\Trolltech\Code_less_create_more\Trollte ch\Code_less_create_more\Troll\4.6\qt\src\winmain/qtmain_win.cpp:93: error: undefined reference to `_Unwind_Resume'
C:\qt-greenhouse\Trolltech\Code_less_create_more\Trollte ch\Code_less_create_more\Troll\4.6\qt\src\winmain/qtmain_win.cpp:135: error: undefined reference to `_Unwind_Resume'
error: collect2: ld returned 1 exit status


Qt is so full of bugs....

wysota
6th November 2010, 23:20
It's not a bug in Qt, you know... You're obviously doing something wrong.

fervenceslau
7th November 2010, 00:06
Qt has a lot of issues with windows... I read in a lot of forums about the errors when trying to compile qt programs with dos, and its the same error...

everyone says its something about the g++ compiler... but in the end no one solve this problem... It kinda sucks and makes us give up qt programing...

And yes, I may be doing something wrong, but the code is right. The problem may be while compiling the code or something... Ill never figure it out and no one will ever solve this, thats whats going to happen uehuehue.

wysota
7th November 2010, 00:12
Somehow I never have any serious problems with Qt on Windows. Maybe the packages I download are less buggy than the ones you download. But then I'm not pressing buttons randomly to see what happens. I'm still convinced you (as a human) messed up your installation yourself.

fervenceslau
7th November 2010, 00:14
Good thing you dont press random buttons, care sharing any info on that? :D

wysota
7th November 2010, 00:16
Good thing you dont press random buttons, care sharing any info on that? :D

Here is the info: http://doc.qt.nokia.com. Read it all a couple of times. It's not 'matrix', I can't transfer all I know to you in a blink of an eye.

fervenceslau
7th November 2010, 00:37
Gee that is rough. All I need is a free-problems compiler =/...
I dont have the time to read all that, maybe ill use my vacation time doing that...

wysota
7th November 2010, 00:42
All I need is a free-problems compiler =/...
You're not having a problem with the compiler. Analyze the two different situations you had here and ask yourself whether a compiler might have caused it (especially the sole fact that some code compiles even when it shouldn't and then you press some button and something totally different happens). Provided you know how compilers work but I'm assuming you do.

fervenceslau
7th November 2010, 01:02
I think i got it working...
But i have to ask: What happens when i put two paths in the environment variables that has mingw on them, this could lead to problems latter, right?

I reinstalled qt due to some problems trying to compile it with source, and then i realized that i had a path that had an older version of mingw.
I removed it and apparently its working...

The thing about graphic programming is that its hard to learn when you're new to it. And the logic behind the program you wanna make is easier to program.
Thats whats most annoying about it.

Anyway, ill keep digging more from nokia's reference and see what else i can learn...
Thx for all your help (and i know your already tired of me hehe)

wysota
7th November 2010, 01:32
But i have to ask: What happens when i put two paths in the environment variables that has mingw on them, this could lead to problems latter, right?
It could lead to problems, yes. The first toolchain in path will be used but if there is something missing in it, some subset of the other installation can be used.


The thing about graphic programming is that its hard to learn when you're new to it. And the logic behind the program you wanna make is easier to program.
By "graphic programming" you mean a graphical user interface? You have to start thinking "asynchronous", that's true. With text-based code you usually have a linear execution flow.