qDebug() and qInfo() error code will never be executed
-
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!)
-
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!)
@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
-
Hi,
Do you have any condition before that line ? If so, are you sure it allows to go through that line ?
-
There is high possibility that a return statement is before that line which will be executed every time.
-
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!)
-
@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
@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 bothqInfo(), andqDebug()works (I mean beforereturn)
But one side question, which is more common between these two for sending out messages, please?@J-Hilk
No, I have't got that. -
@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 bothqInfo(), andqDebug()works (I mean beforereturn)
But one side question, which is more common between these two for sending out messages, please?@J-Hilk
No, I have't got that.Another side question:
When we declare some functions under theprivate slotsaccess 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 underprivate/publiccan't be used for signal-slot connections either, but they can be used like any ordinary C++ function. Are these right please? -
Another side question:
When we declare some functions under theprivate slotsaccess 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 underprivate/publiccan't be used for signal-slot connections either, but they can be used like any ordinary C++ function. Are these right please? -
@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.
-
@J.Hilk
Thanks.
But can functions defined underprivate/publicmodifier be used forsignalstoo?@tomy said in qDebug() and qInfo() error code will never be executed:
@J.Hilk
Thanks.
But can functions defined underprivate/publicbe used forsignalstoo?actually no, a signal may not have a function body defined, IIRC.
-
@tomy said in qDebug() and qInfo() error code will never be executed:
@J.Hilk
Thanks.
But can functions defined underprivate/publicbe used forsignalstoo?actually no, a signal may not have a function body defined, IIRC.
@J.Hilk Thanks.
I meant just slots.To sum up, can we say that all slots whether defined under
private slotsmodifier or ordinary private/public modifiers can be used with or without a connection macro, but only those slots that are defined underprivate/public slotscan be used by theconnectionmacros?I mean, the keyword
slotsin the header file must have a role. Mustn't it? -
Did you already read the dedicated chapter in Qt's documentation ?
-
@J.Hilk Thanks.
I meant just slots.To sum up, can we say that all slots whether defined under
private slotsmodifier or ordinary private/public modifiers can be used with or without a connection macro, but only those slots that are defined underprivate/public slotscan be used by theconnectionmacros?I mean, the keyword
slotsin the header file must have a role. Mustn't it?@tomy
I would recommend reading through @SGaist link, it's essential ;-)To answer your question,
in c++ something like
slotsandsignalsor really any additional keywords are strictly prohibited inside the class header.Therefore slots and signals are actually just
voidkeywords 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
...