我有一个基于QDialog的类。
我有一个QEditLine *editLine和QButton *button。
我使用按钮的clicked()信号。editLine的editingFinished()信号。
当我更改editLine中的文本并按下按钮时,首先会发出editingFinished()信号。在slot方法中,我调用了QMessageBox::question()。在那之后,我不能接收到我的按钮的clicked()信号。
我尝试使用Qt::QueuedConnection作为连接方法,但无济于事。
如何解决我的问题?
发布于 2012-10-17 16:21:56
我认为问题是消息框的事件循环阻塞了主事件循环,因此按钮的信号不会发出。但是如果你打开了一个模式对话框,你打算如何点击这个按钮呢?
发布于 2012-10-17 22:00:35
代码如下:
Window::Window(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
appPath = QApplication::applicationDirPath();
connect(pButton, SIGNAL(clicked()), this, SLOT(build()), Qt::QueuedConnection);
connect(pLineEdit, SIGNAL(editingFinished()), this, SLOT(pathChanged()), Qt::QueuedConnection);
}
void Window::pathChanged()
{
QString path = pLineEdit->text();
if(createPath(path))
updatePath(path);
}
bool Window::createPath(QString path)
{
if(!QDir(path).exists())
{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("Folder is not exist"), "Folder " + path + " is not exist. Do you want to create it?", QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes)
{
QDir dir;
dir.mkpath(path);
}
}
return true;
}
class Window : public QDialog, public Ui::GLConverterDialogUI
{
Q_OBJECT
public:
Window(QWidget *parent = 0);
~Window(void);
......
}发布于 2012-10-18 14:37:54
我在另一个应用程序中也遇到了同样的问题。我使用一些库。我猜这个库使用了QAbstractButton的按下()信号,而不是单击()。而且当我在按下按钮后调用QFileDialog::getSaveFileName()时,似乎也没有调用mouseReleaseEvent()。所以关闭对话框后,按钮仍然被按下,我必须手动发送MouseButtonRealese事件。也许我应该用一些特殊的参数来调用对话框?
https://stackoverflow.com/questions/12929718
复制相似问题