Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I stop QT writing to console?

How do I stop QT writing to console?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Moschops
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • O Offline
      O Offline
      oncaphillis
      wrote on last edited by
      #2

      Is simple redirection on the command line a solution ?

      command >/dev/null 2>&1

      But then it is totally silent

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Moschops
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • O Offline
          O Offline
          oncaphillis
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tom C
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved