久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Q_OBJECT 拋出“對 vtable 的未定義引用"錯誤

Q_OBJECT throwing #39;undefined reference to vtable#39; error(Q_OBJECT 拋出“對 vtable 的未定義引用錯誤)
本文介紹了Q_OBJECT 拋出“對 vtable 的未定義引用"錯誤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 Windows 7 Ultimate 32 位上使用 Qt Creator 2.0.1 和 Qt 4.7.0(32 位).

I'm using Qt Creator 2.0.1 with Qt 4.7.0 (32 bit) on Windows 7 Ultimate 32 bit.

考慮以下代碼,這是產生錯誤的最低限度:

Consider the following code, which is a minimum to produce the error:

class T : public QObject, public QGraphicsItem
{
    Q_OBJECT

public:
    T() {}

    QRectF      boundingRect() const {return QRectF();}
    void        paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
                      QWidget *widget) {}
};

int main()
{
    T t;
    return 0;
}

以上代碼片段導致以下鏈接器錯誤:

The above code fragment causes the following linker errors:

在函數‘T’中:

未定義的對`vtable for T'的引用

undefined reference to `vtable for T'

未定義的對`vtable for T'的引用

undefined reference to `vtable for T'

在函數`~T'中:

未定義的對`vtable for T'的引用

undefined reference to `vtable for T'

未定義的對`vtable for T'的引用

undefined reference to `vtable for T'

如果我注釋掉包含 Q_OBJECT 的行,它編譯正常.我需要帶有 QGraphicsItem 的信號和插槽,所以我需要 Q_OBJECT.

If I comment out the line that contains Q_OBJECT, it compiles fine. I need signal and slots with QGraphicsItem so I need Q_OBJECT.

代碼有什么問題?謝謝.

What is wrong with the code? Thanks.

推薦答案

這是因為 MOC 生成的單元未包含在鏈接過程中.或者它根本沒有生成.我要做的第一件事是將類聲明放在一個單獨的頭文件中,也許構建系統沒有掃描實現文件.

It is because the unit generated by MOC isn't included in the linking process. Or maybe it isn't generated at all. The first thing I'd do is to put the class declaration in a separate header file, perhaps the build system isn't scanning implementation files.

還有一種可能是這個類曾經不屬于Qt元對象系統(也就是說,它沒有Q_OBJECT或者可能根本沒有繼承自QObject),所以需要再次運行qmake才能順序為 MOC 創建必要的規則.強制運行 qmake 的最簡單方法是對項目文件進行一些微不足道的更改以更新其時間戳,例如添加然后刪除一些空格.或者,如果您使用的是 Qt Creator,則只需從項目上下文菜單中選擇運行 qmake"即可.

Another possibility is that the class in question once didn't belong to Qt meta object system (that is, it had no Q_OBJECT or maybe didn't inherit from QObject at all), so qmake needs to be run again in order to create the necessary rules for MOC. The easiest way to force qmake to be run is to make some insignificant changes to the project file to update its timestamp, like adding and then removing some white space. Or, if you're using Qt Creator, then just select "Run qmake" from the project context menu.

這篇關于Q_OBJECT 拋出“對 vtable 的未定義引用"錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 欧美精品一二三区 | 狠狠操狠狠操 | 国产一区二区三区在线看 | 亚洲日韩中文字幕 | 亚洲一区二区中文字幕 | 国产一级一片免费播放 | 久久久久久一区 | 欧美精品福利 | 国产精品久久久久久久一区探花 | 久久精品成人一区 | 欧美中文字幕在线观看 | 亚洲第一视频网 | 免费小视频在线观看 | 精品美女视频在免费观看 | 亚洲欧美中文日韩在线v日本 | 日韩电影一区二区三区 | 精品一区在线 | 日韩电影一区 | 亚洲国产精品一区二区久久 | 久久久久国产精品www | 9久9久 | 91精品国产欧美一区二区成人 | 成人精品一区二区 | 亚洲色图插插插 | 日韩成人av在线 | 日韩在线观看一区 | 国产91久久久久蜜臀青青天草二 | 91麻豆产精品久久久久久 | 欧美黄色录像 | 在线观看国产视频 | 成年人在线电影 | 一区二区三区中文字幕 | 精品三区 | 先锋资源网站 | 国产精品一区二区不卡 | 欧美日韩一区二区三区不卡视频 | 久久91精品国产一区二区 | 精品日韩一区二区三区av动图 | 午夜精品久久久久久久久久久久久 | 二区精品 | 欧美456 |