我有一个mainWindow类,当双击QTabBar时调用函数mainWIndow::ShowDialogBox()
。对话框显示,但不是连接按钮。我在ShowDialogBox中进行了连接调用。它给了我一个关于连接的红色下划线
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的新手。
答案 0 :(得分:0)
行:
connect(dialogButton, SIGNAL(accepted()), dialog, SLOT(accept()));
应该是:
connect(dialogButton, SIGNAL(accepted()), &dialog, SLOT(accept()));
因为第三个参数必须是内存地址(指针)。