Geore Shg
Geore Shg

Reputation: 1329

Qt Undefined Reference To

I had some messy code so I finally seperated it into headers and sources, but now I get 136 warnings saying

inline function 'void suchandsuch()' used but never defined

and errors

undefined reference to 'Widget::Widget(QWidget*)'

I've tried QMake, all the sources are in .pro file, rebuilding, cleaning and deleting all the moc files.

Upvotes: 3

Views: 8827

Answers (1)

Tyler Gill
Tyler Gill

Reputation: 891

The first problem is in the inline functions. If you're familiar with template functions, inline functions have the same requirements. They need to have their implementation details included in the header file so that the compiler can generate the code inline whenever its included somewhere else. You can't implement then in the regular .cpp file.

As for the second problem, if Widget::Widget() is referring to the QWidget class and wasn't copy pasted from the error log, I'm guessing that it means your code isn't linking properly against the QtGui library. Make sure the .pro file doesn't have a line removing it as its otherwise included by default (aka, you don't want a line saying QT -= gui).

If that's not the problem and the Widget class it can't find a Widget(QWidget*) constructor for is your own class, then the problem might just be that there isn't an implementation in the widget's .cpp file for a Widget::Widget(QWidget*) function.

Upvotes: 3

Related Questions