我有一個mainWindow類,當雙擊QTabBar時調用函數mainWIndow::ShowDialogBox()
。該對話框出現,但它沒有連接按鈕。我在ShowDialogBox中有連接調用。它給了我一個紅色下劃線上連接話說QDialogButtonBox按鈕好吧,不要在連接之後再打
no instance of overloaded function "MainWindow::connect" matches the argument list"
這是我的代碼
bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
if (object == mTabWidget->getTabBar() && event->type() == QEvent::MouseButtonDblClick)
{
qDebug()<<"dblclk";
ShowDialogBox();
}
return QObject::eventFilter(object, event);
}
//Show dialog box when double clicked on QTabBar
void MainWindow::ShowDialogBox(){
QDialog dialog;
QVBoxLayout layout(&dialog);
QLineEdit editLine;
layout.addWidget(&editLine);
QDialogButtonBox *dialogButton = new QDialogButtonBox(QDialogButtonBox::Ok);
connect(dialogButton, SIGNAL(accepted()), dialog, SLOT(accept())); //this 'connect' is underlined
layout.addWidget(dialogButton);
dialog.setLayout(&layout);
if(dialog.exec() == QDialog::Accepted)
{
mTabWidget->setTabText(0, editLine.text());
}
}
我已經加入的信號和插槽mainWindow.h作爲
private slots:
void accept();
signals:
void accepted();
我不得不花費數小時在這但沒有運氣。我是Qt新手。
你有沒有實現你的MainWindow :: connect功能? – Iuliu 2014-11-22 18:54:45
@luliu:不需要嗎?正如我所說我是新的,所以不能真正弄清楚。 – user2 2014-11-22 18:56:13
沒有...... MainWindow繼承QMainWindow嗎?如果你用'QObject :: connect'替換'connect'會發生什麼? – Iuliu 2014-11-22 19:38:47