PDA

View Full Version : Qt Console application in Ubuntu



feraudyh
22nd November 2013, 21:05
Hello,
I usually run Qt in Windows.
I created a Qt Console Application in Ubunti with the following code:


#include <QtCore/QCoreApplication>
#include <QtDebug>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug()<<"Hello World\n";

return a.exec();
}

unfortunately it displays nothing at all, like it does in Windows.
There is a config += console in the project file.
What did I do wrong?

ChrisW67
23rd November 2013, 04:42
Nothing, the program outputs "Hello World" to the terminal just fine (and then does not terminate). How are you starting the program?

feraudyh
23rd November 2013, 08:25
I just click on that run button that looks like a green triangle: |>

I may have screwed up my installation of Qt by installing an (extra?) Qt debugger when one was already installed by default.
Maybe I should uninstall all things Qt and reinstall just QtCreator.

anda_skoa
23rd November 2013, 11:35
You should see the string in the "Application Output" tab in Qt Creator, just like on Windows.

Cheers,
_

feraudyh
23rd November 2013, 13:14
Hi there,
No nothing in the "Application Output" tab.
Nothing in the console either.
If I change the program to add

#include <stdio.h>
...
printf("Hello again\n");

there is no visible effect.
What's more I have uninstalled QtCreator and it asked me to uninstall "debug symbols for Qt Creator"
I also uninstalled Qt Linguist and Qt Designer.
Then I reinstalled Qt Creator.
The application still displays nothing.

Radek
23rd November 2013, 15:44
One possible cause: Qt Creator does not cooperate well with every Linux terminal. Check the terminal setting and make sure that it is xterm -e and not econsole -e or something similar. Try again (try the printf() first).

I have solved this in Debian but I have got an error output in "Application Output" window at least. The Creator tried some piping somewhere and failed. Setting the console to xterm solved the problem.

feraudyh
23rd November 2013, 16:38
Thanks,
Could you be more explicit on how you change a terminal setting?

Radek
23rd November 2013, 16:52
Tools -> Options -> Environment

feraudyh
24th November 2013, 09:23
Thanks Radek. This solved the problem.
I put xterm -e instead of the initial x-terminal-emulator -e
The trouble is that this part of the options is very obscure, no drop down list.

MI
28th February 2014, 19:53
Advice :: remember to always use qDebug()<< function for output in ubuntu/linux because cout<< works only in windows and not in ubuntu/linux

ChrisW67
28th February 2014, 21:12
Umm, no... std::cout is a standard part of the C++ library and is fully functional in both environments.

MI
1st March 2014, 17:54
ChrisW67:: i tried cout<< in ubuntu and it didn't work thats way i made this wrong conclusion but when i tried it again and it worked .... see this is what happens when a newbie gives advice he spoiled it all by saying something stupid:confused:

Another advice this time its not wrong::qDebug()<< is for outputing std strings and QStrings but cout<< is only for outputing std strings

so thanks chrisw67 for correcting my mistake

MI
15th March 2014, 09:50
Just one more thing :: i noticed that in linux ubuntu if i dont use endl after cout<< statment the output doesn't show up ... so i googled it up and i foundout that it has somthing to do with flushing the buffer and apparently in windows this is done for you by the os(automatique buffer flushing) but not in ubuntu(no automatique buffer flushing) so you have to use endl after every cout<< statemnt to view the output when in ubuntu and here is a link that explains it all :

http://stackoverflow.com/questions/4751972/c-endl-and-flushing-the-buffer

Radek
15th March 2014, 10:51
No and it isn't in general. It's about buffered I/O. There is a buffer between your app and the output device (for example, cout). As you write on the device, the output isn't written immediately but it is collected by the buffer. When the buffer is full, it is really written and then cleared so that it can get subsequent output. This is because of speed, the output device need not be fast.

The buffer is written immediately if you command flush(). flush() is also made when you are closing the device. On line-oriented devices, (for example cout), it is often made when you command EOL but in general, don't rely on it. Make flush() every time you need to have all so far output on the device right now. You can cout.flush(); or cout << flush;