问题描述:

I would like to create a standalone static library with Qt, using the QApplication class.

So to do that I use a PIMPL, because I wouldn't like to expose any of the Qt classes.

My private implementation looks as simple as this:

class Implementation : public QApplication {

public:

Implementation(int argc, char *argv[]) :

QApplication(argc, argv)

{

}

};

But whenever I try to initiate the library from my test application I get all there errors:

undefined reference to `QApplication::metaObject() const'

Yes! It does make sense. I am getting those because the test application doesn't have any references to Qt's QApplication class.

So how do I use Qt and specifically the QApplication class in my library and still being able to use it in Plain C++ Projects?

网友答案:

Your class definition is missing the Q_OBJECT macro and/or your build system has not run the moc on your file(s).

Furthermore, willing to use the QApplication class in a library is not a typical design pattern. What made you choose QApplication here?

相关阅读:
Top