[問題] 如何實現Qt MainWindow的singleton
架構:
我有個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
04/19 20:52, 1F
→
04/21 19:36, , 2F
04/21 19:36, 2F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章