Results 1 to 14 of 14

Thread: Qt Console application in Ubuntu

  1. #1
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt Console application in Ubuntu

    Hello,
    I usually run Qt in Windows.
    I created a Qt Console Application in Ubunti with the following code:

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QtDebug>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7. qDebug()<<"Hello World\n";
    8.  
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    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: Qt Console application in Ubuntu

    Nothing, the program outputs "Hello World" to the terminal just fine (and then does not terminate). How are you starting the program?

  3. #3
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Console application in Ubuntu

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Console application in Ubuntu

    You should see the string in the "Application Output" tab in Qt Creator, just like on Windows.

    Cheers,
    _

  5. #5
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Console application in Ubuntu

    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.

  6. #6
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt Console application in Ubuntu

    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.

  7. #7
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Console application in Ubuntu

    Thanks,
    Could you be more explicit on how you change a terminal setting?

  8. #8
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt Console application in Ubuntu

    Tools -> Options -> Environment

  9. #9
    Join Date
    Nov 2009
    Location
    Laval, France
    Posts
    124
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt Console application in Ubuntu

    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.

  10. #10
    Join Date
    Feb 2014
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Lightbulb Re: Qt Console application in Ubuntu

    Advice :: remember to always use qDebug()<< function for output in ubuntu/linux because cout<< works only in windows and not in ubuntu/linux
    Last edited by MI; 28th February 2014 at 19:58. Reason: updated contents

  11. #11
    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: Qt Console application in Ubuntu

    Umm, no... std::cout is a standard part of the C++ library and is fully functional in both environments.

  12. #12
    Join Date
    Feb 2014
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Console application in Ubuntu

    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

    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

  13. #13
    Join Date
    Feb 2014
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Console application in Ubuntu

    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/4...ing-the-buffer
    Last edited by MI; 15th March 2014 at 09:52. Reason: spelling corrections

  14. #14
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt Console application in Ubuntu

    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;

Similar Threads

  1. How to exit Qt console application?
    By arcelivez in forum Qt Programming
    Replies: 14
    Last Post: 30th July 2014, 08:51
  2. Replies: 8
    Last Post: 23rd August 2012, 19:28
  3. about console application
    By jirach_gag in forum Qt Programming
    Replies: 2
    Last Post: 5th January 2012, 11:39
  4. console output on windows and ubuntu
    By hannesvdc in forum Qt Programming
    Replies: 2
    Last Post: 11th December 2010, 22:43
  5. Replies: 2
    Last Post: 21st November 2010, 18:03

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.