0

Working on a fairly large chunk of code written by someone else and I am not super familiar with QT, but I haven't had success with recent debugging.

After working great, I added 3 lines, then commented them all out and when testing got many more variations of these two errors:

undefined reference to 'QObject::connectNotify(char const*)' (.rodata._ZTV15NumberWithUnits[_ZTV15NumberWithUnits]+0x60) undefined reference to 'QWidget::x11Event(_XEvent*) (.rodata._ZTV15NumberWithUnits[_ZTV15NumberWithUnits]+0x160)

I'm thinking that there might be some library or other build error, or file cleaning I need to do, but I'm stuck.

After searching and trying multiple things, I found several similar answers such as this one and I was trying to implement adding the -lqt statement or fixing qmake.

Recommendations on either how to do this, or other things to try?

3
  • 1
    Delete the build folder and rebuild the project... Commented Sep 23, 2016 at 20:08
  • Wow, simple fix that worked. I'm having other errors, that I think are unrelated at the moment. Does that happen frequently in the QT environment? Any idea on why/when I might see that? Commented Sep 23, 2016 at 22:21
  • It's because the makefile - qmake's output - depends on all the files qmake scans for input, but it'd slow the build quite a bit if qmake had to re-read them all every time any of them changed. So it doesn't do that. This would be fixable by rearchitecting qmake a bit, but given that qmake as a tool is at end of life, there's little incentive to do so. If you want to avoid that problem, use qbs (Qt build system) or cmake instead. Commented Sep 25, 2016 at 2:47

1 Answer 1

1

Qt relies on a few different types of generated files, and if your build system, whatever it is, doesn't know about those dependencies and doesn't know to re-generate the files when you make changes, then you'll get lots of confusing error messages caused by these generated files being out of date.

In this specific case, the most likely is the "MOC" (meta-object compiler) file being out of date. These files are generated from include files that contain the Q_OBJECT macro, and it's the "moc" utility that creates them.

Other cases include:

  • UI headers, which are generated from the .ui (Qt Designer) files using the "uic" utility
  • Resource files (.cpp), which are generated from the .qrc files using the "rcc" utility.

Ideally, your build system would have dependencies that says that a generated MOC file is dependent on the matching .h file that contains the Q_OBJECT macro, and your build system would then run "moc" to re-generated the file. If your build system isn't doing that, then you're in for a lot of frustration.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer. I must still not be getting how to set all this up. I can't run qmake anymore and get a BIN file generated with all of my .o files after deleting it and rebuilding and running qmake. I have OBJECTS_DIR = ./BIN/ and MOC_DIR = ./BIN/ in my .pro file and I can't figure out how to get rid of the hundreds 'undefined reference to `QChar::QChar(char)' ..etc. errors. I assume that it's due to this build error, but for some reason it's not working for me anymore. My command line attempts were also fruitless. Thoughts?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.