Mat
Mat

Reputation: 481

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

Upvotes: 0

Views: 345

Answers (2)

Kirill Chernikov
Kirill Chernikov

Reputation: 1420

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->listG‌​roup->currentRow()),‌​
     (ui->tableWidgetFiel‌​d->currentRow()+1),
     (‌​ui->actionRemi_mod->‌​isChecked()));
   fields_->show(); 
}

Upvotes: 1

sebter
sebter

Reputation: 46

If you don't need the event loop of exec you can use Dialog->show().

Upvotes: 1

Related Questions