Itay Grudev
Itay Grudev

Reputation: 7463

How can I create a standalone static library using QApplication?

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?

Upvotes: 2

Views: 307

Answers (1)

Jan Kundrát
Jan Kundrát

Reputation: 3816

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?

Upvotes: 4

Related Questions