2

I recently began developing in Qt, but I am having an issue with console projects. When I run my program (Console Program), terminal opens and then immediately closes so I cannot see the output.

Here is the code that I am using:

#include <QtCore/QCoreApplication>
#include <QDebug>
#include <iostream>

int main(int argc, char *argv[])
{
   QCoreApplication a(argc, argv);

qDebug() << "In the stream";

return a.exec();
}

I looked in my project’s .pro file and it seems to be setup correctly (it is configured to use the console with CONFIG += console). I am not sure why the terminal window won’t stay open. I have tried adding system("PAUSE)

This does not work however. I am using Ubuntu and the default Qt Creator settings.

When I run the project I use the default run button, but I have also tried the debug button. The terminal window still just flashes open and then closes before I can see the output. The Application Output pane at the button just says that it is starting the application. This is what my terminal settings look like in QtCreator: x-terminal-emulator -e (this is default)

My QtCreator version is 2.4.1

Could someone tell me how to keep the console/terminal open so I can see the qdebug() output?

Thanks

foobar5512
  • 2,470
  • 5
  • 36
  • 52
  • Is there any information about whether the program exited normally? If it runs, it will stop at a.exec so my guess is somehow there's an error and failed to run. You can check the message by cd to the binary dir and exec the binary in an open terminal. – Min Lin Apr 08 '13 at 01:23
  • When I ./MyExecutable it works fine. But it closes out of terminal immediately with QtCreator still. Do you know what is wrong? Thanks! – foobar5512 Apr 08 '13 at 02:15

2 Answers2

2
  1. Install xterm (sudo apt-get install xterm)
  2. Go to project's run settings and check 'Run in terminal'

Now your console application will use xterm to show itself, but it will fail to debug. The other - safe - way to see console output is to open 'Application Output' (Alt+3). Though it cannot be closed by Ctrl+c (you'll have to use 'stop' button in QtCreator).

Amartel
  • 4,248
  • 2
  • 15
  • 21
1

I've had this problem multiple times before, and it usually means that you're missing a dependency (which is not uncommon on Linux).

How to solve this:

  • Run the executable from the command line. It usually outputs an error message, that could give you additional info onto what the problem actually is

  • If that doesn't work or you need more info, use the ldd command to check dependencies:

      ldd < path to your executable >
    

This will display all the dependencies required and their location - and will also tell you if it can't find one

Once you find the missing dependency (if that's the problem), you can most certainly install it with apt or apt-get

Oxymore-coder
  • 56
  • 1
  • 6