PDA

View Full Version : MDI [Windows XP]



wirasto
26th October 2009, 15:04
First, sorry about my English ;)

If I have opened one dialog, and back to main menu for select another menu, my application crash.

ASSERT: "!activationRecursionGuard" in file widgets\qmenu.cpp, line 961

How fix it ?
Btw, In Linux is fine.

high_flyer
26th October 2009, 15:26
Can you show the relevant code?

wirasto
26th October 2009, 16:05
I'm use QWorkspace as central widget



ws=new QWorkspace(this);

setCentralWidget(ws);



This my menu action


void MainWindow::on_actionKelas_triggered()
{
FrmKelas form(this);
ws->addWindow(&form);
form.exec();
}


void MainWindow::on_actionAnggota_triggered()
{
FrmAnggota form(this);
ws->addWindow(&form);
form.exec();
}


FrmKelas & FrmAnggota inherit QDialog

high_flyer
26th October 2009, 16:27
The problem (I guess) is that you are creating FrmKelas on the stack.
At the same time you are adding it to the mdi area, but as soon as the slot() gets out of scope, your form gets destroyed, living a not legal pointer in the mdi area.

Try allocating your forms on the heap (with 'new') , it should help.

wirasto
26th October 2009, 18:04
Not work :(

This is QMenu bugs (in WinXP) ? I tried open FrmKelas from menu and open FrmAnggota from toolbar. Everything is fine.

wysota
26th October 2009, 22:39
This is a bug in your code and not in QMenu. Focus on correcting your own code instead of chasing non existing bugs in Qt. Try to compose a minimal compilable example reproducing your problem or use a debugger to find out where exactly it crashes. The code you posted doesn't make much sense, by the way. You're starting a modal dialog which at the same time you'd like to be part of MDI. The two don't go together.

wirasto
27th October 2009, 05:28
But, why in Linux is fine?

And, I think, I can opened more dialog if use QAction on QToolbar.

axeljaeger
27th October 2009, 06:45
Just because it works on one OS does not mean you did it right. You should rather try your application on as many operating systems as possible to find bugs that might also affect the other plattforms but not (yet) show up.

I dont think that it makes any difference how to open a dialog, e.g. a QPushButton, a QAction or a QMenu.

wirasto
27th October 2009, 09:10
Really ? well, this is my sample code

mainwindow.h


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QToolBar>
#include <QWorkspace>
#include <QAction>
#include <QMenuBar>

class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);

private:

QToolBar *toolbar;
QAction *toolbar0, *toolbar1;

QWorkspace * ws;

QMenuBar *mainmenu;
QMenu *mn;

private slots:
void bukakelas();
void bukaanggota();

};

#endif // MAINWINDOW_H



mainwindow.cpp


#include "mainwindow.h"
#include <QDialog>

class FrmKelas: public QDialog
{
public:
FrmKelas(QWidget *parent=0):QDialog(parent) { setFixedSize(200, 300); }

};


class FrmAnggota: public QDialog
{
public:
FrmAnggota(QWidget *parent=0):QDialog(parent) { setFixedSize(400, 100); }

};


MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent)
{

toolbar=addToolBar("Tahede");
toolbar0=new QAction(QIcon(":/icon/0.png"), tr("Kelas"), this);
connect( toolbar0, SIGNAL(triggered()), this, SLOT(bukakelas()) );
toolbar1=new QAction(QIcon(":/icon/1.png"), tr("Anggota"), this);
connect( toolbar1, SIGNAL(triggered()), this, SLOT(bukaanggota()) );
toolbar->addAction(toolbar0);
toolbar->addAction(toolbar1);

ws=new QWorkspace(this);
setCentralWidget(ws);

mainmenu=new QMenuBar(this);
setMenuBar(mainmenu);


mn=new QMenu("Master");
//mn->addAction("Kelas", this, SLOT(bukakelas()));
//mn->addAction("Anggota", this, SLOT(bukaanggota()));
mn->addAction(toolbar0);
mn->addAction(toolbar1);
mainmenu->addMenu(mn);
}


void MainWindow::bukakelas()
{
FrmKelas form(this);
ws->addWindow(&form);
form.exec();
}

void MainWindow::bukaanggota()
{
FrmAnggota form(this);
ws->addWindow(&form);
form.exec();
}



main.cpp


#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}



Where I make a mistake?

axeljaeger
27th October 2009, 09:44
When you call exec on a dialog, it will block the application as long as the dialog stays open. Use show instead and create the dialog on the heap instead of the stack.