Results 1 to 7 of 7

Thread: Program compiles but does not run - please help!

  1. #1
    Join Date
    Oct 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Program compiles but does not run - please help!

    My program compiles with the following message (when I press Run):

    "Running build steps for project example1-11...
    Starting: C:/Qt/2009.03/qt/bin/qmake.exe C:/Users/Gaara/Documents/example1-11/example1-11.pro -spec win32-g++ -r
    Exited with code 0.
    Starting: C:/Qt/2009.03/mingw/bin/mingw32-make.exe -w
    mingw32-make: Entering directory `C:/Users/Gaara/Documents/example1-11'
    C:/Qt/2009.03/mingw/bin/mingw32-make -f Makefile.Debug
    mingw32-make[1]: Entering directory `C:/Users/Gaara/Documents/example1-11'
    g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\..\Qt\2009.03\qt\include\QtCore" -I"..\..\..\..\Qt\2009.03\qt\include\QtGui" -I"..\..\..\..\Qt\2009.03\qt\include" -I"..\..\..\..\Qt\2009.03\qt\include\ActiveQt" -I"debug" -I"..\..\..\..\Qt\2009.03\qt\mkspecs\win32-g++" -o debug\main.o main.cpp
    g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\example1-11.exe debug/main.o -L"c:\Qt\2009.03\qt\lib" -lmingw32 -lqtmaind -lQtGuid4 -lQtCored4
    mingw32-make[1]: Leaving directory `C:/Users/Gaara/Documents/example1-11'
    mingw32-make: Leaving directory `C:/Users/Gaara/Documents/example1-11'
    Exited with code 0."

    but the actual program does not run, please let me know if you require more information, you help with be greatly appreciated - thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Program compiles but does not run - please help!

    It seems to run and successfully returns with no error (=0). So how does your main function look like? Do you start the event loop?

  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Program compiles but does not run - please help!

    This usually happens when you create a console application on windows and forget about the CONFIG += console in project file, so make sure it's not this case, and give us more information on what application you make.

  4. #4
    Join Date
    Oct 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program compiles but does not run - please help!

    The program code looks as follows:

    Qt Code:
    1. #include <QTextStream>
    2. #include <QString>
    3. #include <QFile>
    4.  
    5. QTextStream cout(stdout, QIODevice::WriteOnly);
    6. QTextStream cerr(stderr, QIODevice::WriteOnly);
    7.  
    8. int main() {
    9. QString str, newstr;
    10. QTextStream strbuf(&str); /*strbuf is initialized with the address of str.*/
    11.  
    12. int lucky = 7;
    13. float pi = 3.14;
    14. double e = 2.71;
    15.  
    16. cout << "An in-memory stream" << endl;
    17. strbuf << "luckynumber: " << lucky << endl
    18. << "pi: " << pi << endl
    19. << "e: " << e << endl;
    20.  
    21. cout << str;
    22.  
    23. QFile data("mydata");
    24. data.open(QIODevice::WriteOnly);
    25. QTextStream out(&data);
    26. out << str ;
    27. data.close();
    28.  
    29. cout << "Read data from the file - watch for errors." << endl;
    30. if(data.open(QIODevice::ReadOnly)) { /*Make sure the file exists before
    31.   attempting to read.*/
    32. QTextStream in(&data);
    33. int lucky2;
    34. in >> newstr >> lucky2;
    35. if (lucky != lucky2)
    36. cerr << "ERROR! wrong " << newstr << lucky2 << endl;
    37. else
    38. cout << newstr << " OK" << endl;
    39.  
    40. float pi2;
    41. in >> newstr >> pi2;
    42. if (pi2 != pi)
    43. cerr << "ERROR! Wrong " << newstr << pi2 << endl;
    44. else
    45. cout << newstr << " OK" << endl;
    46.  
    47. double e2;
    48. in >> newstr >> e2;
    49. if (e2 != e)
    50. cerr << "ERROR: Wrong " << newstr << e2 << endl;
    51. else
    52. cout << newstr << " OK" << endl;
    53. data.close();
    54. }
    55.  
    56. cout << "Read from file line-by-line" << endl;
    57. if(data.open(QIODevice::ReadOnly)) {
    58. QTextStream in(&data);
    59. while (not in.atEnd()) {
    60. newstr = in.readLine();
    61. cout << newstr << endl;
    62. }
    63. data.close();
    64. }
    65. return 0;
    66. }
    To copy to clipboard, switch view to plain text mode 

    Thank you for the responses.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Program compiles but does not run - please help!

    As said: it runs perfect. what do you expect to "see"? have a look at the console output. (and instead of using cout you can use e.g. qWarning() )

  6. #6
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Program compiles but does not run - please help!

    I see you are using windows, on this OS you need the following line:
    Qt Code:
    1. CONFIG += console
    To copy to clipboard, switch view to plain text mode 
    in your project file (the .pro file) whenever you are creating console application
    After you add that line in your .pro file, rebuild your application and it should open the console as expected.

  7. The following user says thank you to Zlatomir for this useful post:

    zoz (11th October 2010)

  8. #7
    Join Date
    Oct 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program compiles but does not run - please help!

    sorted, thanks allot.

    I added: CONFIG += console
    as advised and
    In Projects mode, chose the Run Settings tab and checked the "Run in Terminal".

Similar Threads

  1. Replies: 3
    Last Post: 18th August 2010, 19:33
  2. Replies: 4
    Last Post: 22nd July 2010, 15:46
  3. [SOLVED] 64 bit compiles under Visual Studio 2005
    By drescherjm in forum Installation and Deployment
    Replies: 1
    Last Post: 27th May 2009, 17:32
  4. wrong connection? program crashes altough it compiles
    By cbarmpar in forum Qt Programming
    Replies: 7
    Last Post: 30th September 2008, 12:48

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.