How do I stop QT writing to console?



  • I start my QT application (on Linux, from the command line), and interact with it. Every so often, it dumps a string to the command line; usually a whinge about how a slot doesn't exist so a signal can't be connected, or maybe QTextCursor::setPosition: Position '-1' out of range or some other such.

    I find lots of information about how I can get QT to output this sort of thing; how can I stop it polluting the console?



  • Is simple redirection on the command line a solution ?

    command >/dev/null 2>&1

    But then it is totally silent



  • The intention is that the user should not under ordinary circumstances have messages presented in the console, so silent is fine.

    I'd rather not have to do some command-line fu to get this right; the current requirement is that the user should be able to start the application with no more than typing the name of the application at the command line, so a fix that requires them to do more is off the table at the moment.



  • In the Code you may achieve the same effect with

    int fd = ::open("/dev/null/",O_WRONLY,0744 );
    if(fd!=-1)
    {
    dup2(fd,1)
    dup2(fd,2)
    close(fd);
    }

    A simpler solution ould be to simply wrte a bash frontend like
    /bin/application which does

    #!/bin/bash

    /bin/application-bin >/dev/null 2>&1



  • You can change where Qt prints out debug messages, warnings, critical and fatal error messages by installing a new message handler.

    See the documentation :
    http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#qInstallMessageHandler

    For example, you can choose to redirect them in a log file.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.