[問題] 如何實現Qt MainWindow的singleton

看板C_and_CPP (C/C++)作者 (RR)時間16年前 (2010/04/19 17:42), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
架構: 我有個Qt程式,是用Qt Creator先建構主體的。 有一個class主要是瀏覽器,也就是MainWindow所在... 另一個class則是接收IR event,且稱為IR class吧 問題: 在IR class接收到特定的IR event後,我想要MainWindow內的瀏覽器原件(WebView) 去顯示某個特定的URL。 但我現在不知如何在IR class內取得MainWindow class instance... 目前的想法是在MainWindow內定一個static method給IR class呼叫, 但再來就不知怎麼做下去了........:( main.cpp Code: /* macro for a safe call to DirectFB functions */ #define DFBCHECK(x...) \ do \ { \ some code... \ } while(0) pthread_t ir_thread_id; void *irthread(void *arg) { do { // 收到特定IR code... MainWindow::fireXEvent(); } while(bool) } int main(int argc, char *argv[]) { QApplication a(argc, argv); // MainWindow* w=MainWindow::getInstance(); MainWindow w; w.setFont(QFont("TTF font", 14, QFont::Normal, false)); w.show(); // some code... } ---------------------------------------------------------- mainwindow.h code: class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0); static void fireXEvent(); // some code... } ---------------------------------------------------------- mainwindow.cpp void MainWindow::fireXEvent() { // 在這邊,如果說已經被呼叫到了 // 我該如何在這個static method內呼叫到WebView這個member? } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.250.38.86

04/19 20:52, , 1F
用signal/slot串起來就好了
04/19 20:52, 1F

04/21 19:36, , 2F
謝謝,已經解決
04/21 19:36, 2F
文章代碼(AID): #1Bp2MIMh (C_and_CPP)
文章代碼(AID): #1Bp2MIMh (C_and_CPP)