PDA

View Full Version : How to compile Qt (linux) progect in windows? (runtime error)



mandarinka
7th March 2011, 12:21
Hello!
I have a project that works in Qt4 on ubuntu.
It use <QWidget>, <QFile>, <QTextStream>;
<QDateTime>;
and <stdio.h>, <stdlib.h>, <time.h> (to generate random numbers).

Now I want to make it work on windows. I've installed Qt SDK on windows, opened my .pro and run it. But following error occured:

Runtime Error!
This application has requested the Runtime to terminate it in a usual way.


I've found some information in Internet. It says that problem is with .dlls:
here (http://www.thelins.se/johan/blog/2010/06/dlls-from-qt-sdk/)

The SDK comes with two sets of dlls. One set resides in $BASEDIR/bin and the other in $BASEDIR/qt/bin. The former contains the dlls used by Qt Creator, while the latter are the dlls that you want to ship with your executable.

But what sould I do to solve my problem? How to find out what .dlls and where I have to fix?

qlands
7th March 2011, 12:38
Hi,

If the problem is that the application does not find a dll, you will get a window saying "Unable to find xxx.dll"

If you application crashes, this means that there is something wrong with it. Try to run it using the debug.

Carlos.

mandarinka
7th March 2011, 20:48
I've run my other applications, that work just fine in ubuntu, but in windows they don't. Most of them don't give any error messages: they just don't write to file or don't generate random number.
As far as I understand, I have to use the same c++ compiler and c++ libraries I've used in ubuntu.
1) How to find out what compiler and libraries I've used in ubuntu Qt Creator?
2) How to compile the same compiler and libraries in windows Qt Creator?

schnitzel
7th March 2011, 20:57
Hello!
I have a project that works in Qt4 on ubuntu.
It use <QWidget>, <QFile>, <QTextStream>;
<QDateTime>;
and <stdio.h>, <stdlib.h>, <time.h> (to generate random numbers).

Now I want to make it work on windows. I've installed Qt SDK on windows, opened my .pro and run it. But following error occured:


I've found some information in Internet. It says that problem is with .dlls:
here (http://www.thelins.se/johan/blog/2010/06/dlls-from-qt-sdk/)


But what sould I do to solve my problem? How to find out what .dlls and where I have to fix?

can you build/run any of the supplied examples successfully on windows?

mandarinka
7th March 2011, 21:32
can you build/run any of the supplied examples successfully on windows?

On windows I can build and run one application - it's a simple window, with some text and table. But this table is not filled with data from existed text file (this application successfully fills this table on ubuntu).
There is also a warning: Qmake does not support buuild directories below the source directory.

schnitzel
7th March 2011, 21:48
On windows I can build and run one application - it's a simple window, with some text and table. But this table is not filled with data from existed text file (this application successfully fills this table on ubuntu).
There is also a warning: Qmake does not support buuild directories below the source directory.

Qt now uses shadow builds - try googling that.

Regarding the text file... are you sure that your application can find the text file when you run it?
Why don't you show the code of your simple app so we can help you better.

mandarinka
7th March 2011, 22:10
...are you sure that your application can find the text file when you run it?
It seems that it can't... But why? I have this text file in the same directory with .pro, .cpp and .h files. And this directory is on the same disс, where Qt SDK is installed.



QFile file("words.txt");
QString str;
QList<QPair< QString,QList<QString> > > list;
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream(&file);
while(!stream.atEnd())
{
str = file.readLine();
...and store this lines in list
}
}

ChrisW67
7th March 2011, 22:12
Hello!
Now I want to make it work on windows. I've installed Qt SDK on windows, opened my .pro and run it. But following error occured:

Runtime Error!
This application has requested the Runtime to terminate it in a usual way.


When you say "opened my .pro file an run it," what exactly do you mean? You don't "run" a project file; it is an input file to a build process that may produce something that can be run.

The diagnostic message you have given us not very helpful on its own. Did the Qt Creator program, one of the Qt utilities (qmake or moc), or the compiler/linker itself throw this error message? How/where was the message displayed? Did your program compile cleanly and then fail when run? Does it fail when you run it in the debugger?

Make sure that when you copied your source across to the Windows machine you copied only the source files and left all the intermediate and executable files behind.

Edit:


It seems that it can't... But why? I have this text file in the same directory with .pro, .cpp and .h files. And this directory is on the same disс, where Qt SDK is installed.

On Windows the default behaviour is to build the code and put the intermediate and executable files in to a shadow build directory (one for debug builds and a different one for release builds). When Qt Creator runs the executable the current working directory is the shadow build directory, not the source directory. Since you open the file with a relative path it looks in the current working directory and fails to find the file.

schnitzel
7th March 2011, 22:37
It seems that it can't... But why? I have this text file in the same directory with .pro, .cpp and .h files. And this directory is on the same disс, where Qt SDK is installed.



QFile file("words.txt");
QString str;
QList<QPair< QString,QList<QString> > > list;
if(file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream(&file);
while(!stream.atEnd())
{
str = file.readLine();
...and store this lines in list
}
}


Qt Creator uses shadow build by default. This is a project specific setting in Qt Creator. It means that Qt Creator will never modify any files below the source tree and all temporary and intermediate files will be created 'out of source'. (I think that is the terminology).

Your application clearly expects this file 'words.txt' to be present from wherever your app runs. Hint, it is not in the same folder where your .pro file is. Try going up a folder from where your .pro file is and look for a folder named '<your project>-build-desktop'.

...
while I wrote this post Chris edited his, so ignore my rant :)

ChrisW67
8th March 2011, 23:02
...
while I wrote this post Chris edited his, so ignore my rant :)

Oh, but you put it so eloquently. :D

mandarinka
9th March 2011, 10:05
On Windows the default behaviour is to build the code and put the intermediate and executable files in to a shadow build directory (one for debug builds and a different one for release builds). When Qt Creator runs the executable the current working directory is the shadow build directory, not the source directory. Since you open the file with a relative path it looks in the current working directory and fails to find the file.

Thanks, that's really helped. Now my small applications work perfectly well =) My big application still have problems, but sooner or later I'll solve them.

Could you please explain how to make one working exe-file from my application? I've done the following:
1) I've build Qt statically - in cmd:
>cd C:\path\to\Qt
>configure.exe -static
then >wingw32-make
It tooks a lot of time, then I have some errors (like: wingw32-make[3]: ***[..\..\bin\qmlviever.exe] Error 1)
2) Then I run my small application project in Qt Creator (as reliase). I've found 10Mb .exe file in the shadow build directory. It works fine in my computer. But in other computer (with no Qt or VS) it gives an error: can't find mingwm10.dll.

This are the questions:
1) How to solve this problem with mingwm10.dll? As far as I understand, I have to compile my release version with this library too. But how? I don't want to copy mingwm10.dll in \Windows\System32 on every computer...
2) Now Qt Creator compile everything with the static libraries. Is it possible to choose - to include this libraries in .exe file or not?

schnitzel
9th March 2011, 16:40
The answers to your questions can be found by reading:
http://doc.qt.nokia.com/4.7/deployment.html