Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qDebug() and qInfo() error code will never be executed
Qt 6.12 LTS is out! See what's new in the release blog

qDebug() and qInfo() error code will never be executed

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 5 Posters 6.3k Views 2 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.
  • tomyT tomy

    Hello to all,

    In a C++ code on Qt Creator 4.8.1, I get the error/warning "code will never be executed" for the statement qDebug() << "curFile is "; in a method, although I have included <QDebug>!

    Why please?

    (I used it with the same format as this and it worked before, but I don't know why it's not possible now!)

    aha_1980A Offline
    aha_1980A Offline
    aha_1980
    Lifetime Qt Champion
    wrote on last edited by aha_1980
    #2

    @tomy are you on a release build?

    I think this is a false positive then. There should already be a bugreport for that.

    Edit: found it: QTCREATORBUG-20963

    Qt has to stay free or it will die.

    tomyT 1 Reply Last reply
    6
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #3

      Hi,

      Do you have any condition before that line ? If so, are you sure it allows to go through that line ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Maaz MominM Offline
        Maaz MominM Offline
        Maaz Momin
        wrote on last edited by
        #4

        There is high possibility that a return statement is before that line which will be executed every time.

        1 Reply Last reply
        3
        • tomyT tomy

          Hello to all,

          In a C++ code on Qt Creator 4.8.1, I get the error/warning "code will never be executed" for the statement qDebug() << "curFile is "; in a method, although I have included <QDebug>!

          Why please?

          (I used it with the same format as this and it worked before, but I don't know why it's not possible now!)

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #5

          @tomy
          do you have by any change this

          DEFINES += QT_NO_DEBUG_OUTPUT

          in your pro file ?


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • aha_1980A aha_1980

            @tomy are you on a release build?

            I think this is a false positive then. There should already be a bugreport for that.

            Edit: found it: QTCREATORBUG-20963

            tomyT Offline
            tomyT Offline
            tomy
            wrote on last edited by tomy
            #6

            @aha_1980
            I face it while using the debug mode!
            Either it's an error or simply a warning, it prohibits the code (that line) from executing.

            @SGaist
            Hi, Yes, it's inside an if-condition, but it oughtn't to be an issue. That output must be printed when the condition is accepted and not otherwise. So, there shouldn't actually be a warning/error, I suppose.

            @Maaz-Momin, you hit the nail on the head!
            Exactly. And it was the source of the issue indeed. Because when a function is going to be returned, there mustn't be any other code left. I hadn't noted that accurately enough, unfortunately.
            Solved, thanks. Now both qInfo(), and qDebug() works (I mean before return)
            But one side question, which is more common between these two for sending out messages, please?

            @J-Hilk
            No, I have't got that.

            tomyT 1 Reply Last reply
            0
            • tomyT tomy

              @aha_1980
              I face it while using the debug mode!
              Either it's an error or simply a warning, it prohibits the code (that line) from executing.

              @SGaist
              Hi, Yes, it's inside an if-condition, but it oughtn't to be an issue. That output must be printed when the condition is accepted and not otherwise. So, there shouldn't actually be a warning/error, I suppose.

              @Maaz-Momin, you hit the nail on the head!
              Exactly. And it was the source of the issue indeed. Because when a function is going to be returned, there mustn't be any other code left. I hadn't noted that accurately enough, unfortunately.
              Solved, thanks. Now both qInfo(), and qDebug() works (I mean before return)
              But one side question, which is more common between these two for sending out messages, please?

              @J-Hilk
              No, I have't got that.

              tomyT Offline
              tomyT Offline
              tomy
              wrote on last edited by
              #7

              Another side question:
              When we declare some functions under the private slots access modifier, they can be used "only" inside signal-slot connections, and we "cannot" use them as ordinary C++ functions. On the other hand, those functions defined under private/public can't be used for signal-slot connections either, but they can be used like any ordinary C++ function. Are these right please?

              J.HilkJ 1 Reply Last reply
              0
              • tomyT tomy

                Another side question:
                When we declare some functions under the private slots access modifier, they can be used "only" inside signal-slot connections, and we "cannot" use them as ordinary C++ functions. On the other hand, those functions defined under private/public can't be used for signal-slot connections either, but they can be used like any ordinary C++ function. Are these right please?

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #8

                @tomy
                nope,
                the best thing about signals and slots is, that you can call any signal and any slot like it is a normal function - because it actually is a normal function.

                The only restriction is the private and public modifier.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                tomyT 1 Reply Last reply
                2
                • J.HilkJ J.Hilk

                  @tomy
                  nope,
                  the best thing about signals and slots is, that you can call any signal and any slot like it is a normal function - because it actually is a normal function.

                  The only restriction is the private and public modifier.

                  tomyT Offline
                  tomyT Offline
                  tomy
                  wrote on last edited by tomy
                  #9

                  @J.Hilk
                  Thanks.
                  But can functions defined under private/public modifier be used for signals too?

                  J.HilkJ 1 Reply Last reply
                  0
                  • tomyT tomy

                    @J.Hilk
                    Thanks.
                    But can functions defined under private/public modifier be used for signals too?

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #10

                    @tomy said in qDebug() and qInfo() error code will never be executed:

                    @J.Hilk
                    Thanks.
                    But can functions defined under private/public be used for signals too?

                    actually no, a signal may not have a function body defined, IIRC.


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    tomyT 1 Reply Last reply
                    2
                    • J.HilkJ J.Hilk

                      @tomy said in qDebug() and qInfo() error code will never be executed:

                      @J.Hilk
                      Thanks.
                      But can functions defined under private/public be used for signals too?

                      actually no, a signal may not have a function body defined, IIRC.

                      tomyT Offline
                      tomyT Offline
                      tomy
                      wrote on last edited by
                      #11

                      @J.Hilk Thanks.
                      I meant just slots.

                      To sum up, can we say that all slots whether defined under private slots modifier or ordinary private/public modifiers can be used with or without a connection macro, but only those slots that are defined under private/public slots can be used by the connection macros?

                      I mean, the keyword slots in the header file must have a role. Mustn't it?

                      J.HilkJ 1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        Did you already read the dedicated chapter in Qt's documentation ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        4
                        • tomyT tomy

                          @J.Hilk Thanks.
                          I meant just slots.

                          To sum up, can we say that all slots whether defined under private slots modifier or ordinary private/public modifiers can be used with or without a connection macro, but only those slots that are defined under private/public slots can be used by the connection macros?

                          I mean, the keyword slots in the header file must have a role. Mustn't it?

                          J.HilkJ Offline
                          J.HilkJ Offline
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #13

                          @tomy
                          I would recommend reading through @SGaist link, it's essential ;-)

                          To answer your question,

                          in c++ something like slots and signals or really any additional keywords are strictly prohibited inside the class header.

                          Therefore slots and signals are actually just void keywords for the regular compiler. However they are needed for the meta object compiler to search for function names and arguments to do the connect magic.

                          However this is also only true if you use the old Qt4 Syntax, with the new Qt5 one the receiving function can quite literally be anything.

                          • normal functions
                          • other signals (signal-signal is also possible with qt4 synt)
                          • slots
                          • lambdas
                            ...

                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          1 Reply Last reply
                          1

                          • Login

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