1
我是Qt Creator的新手。我已使用「表單」文件mainwindow.ui
創建菜單menuFile
,其中操作爲actionOpen
。鏈接GUI創建菜單到SLOT Qt
我已經搜查谷歌,但一切我覺得編程創建菜單和鏈接SLOT
那兒。
如何將SLOTS
從mainwindow.ui
文件鏈接到mainwindow.cpp
文件?
我是Qt Creator的新手。我已使用「表單」文件mainwindow.ui
創建菜單menuFile
,其中操作爲actionOpen
。鏈接GUI創建菜單到SLOT Qt
我已經搜查谷歌,但一切我覺得編程創建菜單和鏈接SLOT
那兒。
如何將SLOTS
從mainwindow.ui
文件鏈接到mainwindow.cpp
文件?
您可以訪問設計師添加了動作線槽ui
成員在類(最有可能是一個指針,如果它是一個對象使用運營商訪問的成員。),像這樣:
//in the constuctor you connect the action with the slot
connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(OpenTriggered()));
//...
//and define the slot (don't forget to declare it as a slot in the .h file)
//and replace MainWindow with your class name
void MainWindow::OpenTriggered()
{
QMessageBox::warning(this, "Open", "Open triggered");
}
,以後你可能需要一個可檢查的作用,那麼你可以使用toggled信號,或triggered(bool)
不知道你的意思究竟是什麼,但在Qt Designer中,你可以去在動作編輯器,然後用鼠標右鍵單擊上市的QAction和然後點擊「轉到插槽...」。它會自動生成代碼,您只需添加所需的行爲。 – gpalex