1. 程式人生 > >Qt_幾個錯誤

Qt_幾個錯誤

1、在其他類裡面想要用MainWindow的槽函式
一開始想在其他類裡新建一個MainWindow,結果遞迴了,只用一個空指標的話直接就報錯崩了,最後通過傳值的形式把MainWindow傳到了connect函式裡。
出現ISO C++ forbids declaration of MainWindow with no type,需要在使用MainWindow的類的標頭檔案裡宣告一下MainWindow

#include <QObject>
#include <mainwindow.h>

class MainWindow;

2、error: redefinition of ‘class XXX’

要把class寫到條件編譯的標頭檔案之間

#ifndef XXX_CPP
#define XXX_CPP

//file contents

#endif