undefined reference to vtable for …

余生长醉 提交于 2019-12-01 05:54:40

You can't copy QTcpSockets, so it may cause other cryptic errors if you try to pass them by copy rather than by address.

    HttpProxyThreadBrowser(QTcpSocket * outgoingSocket,QTcpSocket * browserSocket,QObject *parent = 0);

private:
    QTcpSocket* outgoingSocket;
    QTcpSocket* browserSocket;

And completely recompiling your project may help, when you change header files, because qmake generated Makefile can sometimes fail to notice the changes.

The destructor is implicitly virtual because a base class has a virtual d'tor.

The GNU compiler emits the vtable along with the first non-inline virtual method ("key method"). As your d'tor is defined inside the class, it is implicitly virtual, and as there are no other virtual methods, you don't have a key method.

There is no use case where a concrete class would have only virtual inline methods, as they can be inlined only into derived classes.

I'd move the definition of the dtor to the implementation file.

I'm not sure whether you need to use moc here as well, or if QThread derivatives work without (IIRC you need it only for Qt's cast operators, and for signals/slots).

Sys

I had also a undefined reference to vtable error and followed the steps in Undefined reference to vtable... Q_OBJECT macro, that adviced me to run qmake and... it worked!

This is often caused by not linking the files generated by automoc.

First, you need to run automoc on the headers where classes using Q_OBJECT are defined, in your case "httpproxythreadbrowser.h". This will generate a "*.moc" file.

Now there are two common approaches how to continue. Either you can #include the .moc file at the end of your .cpp file with class definition or you can pass it to the compiler as anoher source file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!