Results 1 to 12 of 12

Thread: How to compile Qt (linux) progect in windows? (runtime error)

  1. #1
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    1
    Qt products
    Qt4

    Default How to compile Qt (linux) progect in windows? (runtime error)

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

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to compile Qt (linux) progect in windows? (runtime error)

    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.

  3. #3
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    1
    Qt products
    Qt4

    Default Re: How to compile Qt (linux) progect in windows? (runtime error)

    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?

  4. #4
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to compile Qt (linux) progect in windows? (runtime error)

    Quote Originally Posted by mandarinka View Post
    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


    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?

  5. #5
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    1
    Qt products
    Qt4

    Default Re: How to compile Qt (linux) progect in windows? (runtime error)

    Quote Originally Posted by schnitzel View Post
    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.

  6. #6
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to compile Qt (linux) progect in windows? (runtime error)

    Quote Originally Posted by mandarinka View Post
    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.

  7. #7
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    1
    Qt products
    Qt4

    Default Re: How to compile Qt (linux) progect in windows? (runtime error)

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

    Qt Code:
    1. QFile file("words.txt");
    2. QString str;
    3. QList<QPair< QString,QList<QString> > > list;
    4. if(file.open(QIODevice::ReadOnly | QIODevice::Text))
    5. {
    6. QTextStream stream(&file);
    7. while(!stream.atEnd())
    8. {
    9. str = file.readLine();
    10. ...and store this lines in list
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to compile Qt (linux) progect in windows? (runtime error)

    Quote Originally Posted by mandarinka View Post
    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.
    Last edited by ChrisW67; 7th March 2011 at 22:36.

  9. The following user says thank you to ChrisW67 for this useful post:

    mandarinka (8th March 2011)

  10. #9
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to compile Qt (linux) progect in windows? (runtime error)

    Quote Originally Posted by mandarinka View Post
    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.

    Qt Code:
    1. QFile file("words.txt");
    2. QString str;
    3. QList<QPair< QString,QList<QString> > > list;
    4. if(file.open(QIODevice::ReadOnly | QIODevice::Text))
    5. {
    6. QTextStream stream(&file);
    7. while(!stream.atEnd())
    8. {
    9. str = file.readLine();
    10. ...and store this lines in list
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    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
    Last edited by schnitzel; 7th March 2011 at 22:56.

  11. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to compile Qt (linux) progect in windows? (runtime error)

    ...
    while I wrote this post Chris edited his, so ignore my rant
    Oh, but you put it so eloquently.

  12. #11
    Join Date
    Feb 2011
    Posts
    8
    Thanks
    1
    Qt products
    Qt4

    Default Re: How to compile Qt (linux) progect in windows? (runtime error)

    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?

  13. #12
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to compile Qt (linux) progect in windows? (runtime error)

    The answers to your questions can be found by reading:
    http://doc.qt.nokia.com/4.7/deployment.html

Similar Threads

  1. How do I compile for linux on windows?
    By waitingforzion in forum Newbie
    Replies: 4
    Last Post: 28th December 2009, 07:51
  2. port linux app to win (runtime error)
    By agostain in forum Qwt
    Replies: 3
    Last Post: 9th September 2009, 12:45
  3. Project won't compile under Windows (works under Linux)
    By philski in forum Qt Programming
    Replies: 7
    Last Post: 14th September 2006, 15:29
  4. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05:23
  5. Replies: 4
    Last Post: 12th January 2006, 04:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.