Can't use QMainWindow after opened a QDialog (Qt)
In my program I have the following problem: After I opened a QDialog
from QMainWindow
, I can't use the QMainWindow
, only if I close the QDialog
first. Is there a solution for this?
Thank you,
Mate
如果你不需要exec的事件循环,你可以使用Dialog-> show()。
You problem is that you create your dialog on the stack. That's why you dialog is deleted after on_action_sszes_Mez_rt_k_triggered()
finished. You must create your dialog on the heap:
#include <QMainWindow>
#include <QScopedPointer>
...
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
QScopedPointer<DialogFields> fields_;
};
...
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
field_.reset(new DialogFields());
}
...
void MainWindow::on_action_sszes_Mez_rt_k_triggered()
{
fields_->adatokFogad((ui->listType->currentRow()+1),
(ui->listGroup->currentRow()),
(ui->tableWidgetField->currentRow()+1),
(ui->actionRemi_mod->isChecked()));
fields_->show();
}
链接地址: http://www.djcxy.com/p/39284.html