2

New to QT, I've imported a project someone else made, and it compiles and runs on the MinGW version of QT Creator. But there's a small problem with it, that would be much easier to diagnose if I could see the debug output.

There are lines all over the place like "qInfo() << "debug message";", but I'm not seeing any output from them in the application output window when I run the project in debug mode, which is when I understand it is supposed to be. All I can see after running the program is:

Debugging starts Debugging has finished

What I've tried:

  • Made sure the kit used is the QT debugger and mingw that came with the install

  • Put an ifdef, with "#undef QT_NO_INFO_OUTPUT" at the top of main.cpp

  • Added include QtDebug to all the header files

Still nothing.

What am I doing wrong?

Keep in mind I am new to Qt, maybe one of the things I'm saying I've tried I haven't implemented properly :S

Thanks!

GemmaB89
  • 165
  • 2
  • 16
  • Forget the debug messages for now and see if you can [get the debugger set up](http://doc.qt.io/qtcreator/creator-debugger-engines.html). With the debugger you can step through your code line by line (maybe even step backward) and see exactly what's going on. Much more efficient than playing games with debug statements. – user4581301 Oct 12 '16 at 22:35
  • I have that working actually, it seems that a pointer is being set to zero somewhere, when it's actually needed later. I just have no idea where, and I suspect when it happens one of the debug messages will probably say why – GemmaB89 Oct 12 '16 at 22:40
  • Possibly, but you should also be able to set a breakpoint that will halt the program when the pointer is changed. [Link to command line GDB watchpoint setup](http://stackoverflow.com/questions/6511560/can-i-have-gdb-break-on-read-write-from-an-address), but QT creator will likely have a GUI that makes this easier to set up. – user4581301 Oct 12 '16 at 22:47
  • Do you mean adding data breakpoint? Didn't know you could do that, had a play with it and it seems to kick in at the very end of a function that's requesting an auth to access google drive. Just going out of scope maybe? I think it's just failing to get the auth, but I'm struggling to see why. Stepping backwards would be handy but I can't see an option to do that? – GemmaB89 Oct 12 '16 at 22:58
  • Data breakpoint sounds right. Stepping backwards is kind of rare. Some gdb implementations have it and some don't. Ant the very end of a function, though... Is your pointer scoped inside the function and becoming lost? Are you possibly overrunning the stack and making the return go haywire? Need code to tell. – user4581301 Oct 12 '16 at 23:17

1 Answers1

3

qInfo() qDebug() etc all fall back to a function that can be overriden. Make sure that this isnt done anywhere inside the project, (global search for "qInstallMessageHandler"). If its not implemented, define it yourself like this:

void debugmessagehandler(QtMsgType Type, 
    const QMessageLogContext& Context, 
    const QString &Message) 
{
#ifdef WIN32
    OutputDebugString(reinterpret_cast<const wchar_t *>(m.utf16()));
#endif
}

and register it in your QApplication-object-constructor (or shortly after) like this

this->qInstallMessageHandler(debugmessagehandler);

Now all you need to do is to make sure you debugger is actually attached. You could call

isDebuggerPresent(void);

from winbase.h inside your code to check, or use an external program to verify.

markus-nm
  • 805
  • 5
  • 8
  • So glad I found this post because I just started a new position at a company and started working on a fairly large Qt project; however the previous devs left the company.. Trying to do some simple debugging and _could not_ get qDebug to work was driving me insane. This is was my issue. – Chris Jun 12 '19 at 22:26