PDA

View Full Version : Dialog error in Windows, but not on Mac



mtnbiker66
11th February 2013, 19:10
All --

Just doing some testing to verify that my app works correctly in Windows and Mac, and just noticed that the following code in my mainwindow.cpp works exactly as I expect on my Mac (where I do my primary development), but the same code does not generate the dialog and throws the following error: "QDialog::exec: Recursive call detected" because the dialog isn't created. As this code was written a year ago I'm having trouble believing that I've missed this before but that's another story...

mainwindow.h

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

RAOEntryDialog *RAO_Edit;
};


mainwindow.cpp


//************************************************** **************************
void MainWindow::on_SurgePB_clicked()
{
//**********************************************
//* Create a pop-up dialog to allow the user *
//* to perform large-scale editing of period *
//* and phase data related to RAOs... *
//**********************************************
if (!RAO_Edit)
{
RAO_Edit = new RAOEntryDialog(surgemodel, "SURGE", user, rig_id,
rig_dataset, this);

connect(RAO_Edit, SIGNAL(edit_rao_signal(int)),
this, SLOT(process_rao_edits(int)));
}

RAO_Edit->exec();

}


If instead of the "if" statement I simply create the dialog then delete it after the "exec()" command it works fine - and that's probably a better way of preventing memory leaks anyway - but I was wondering if someone has a theory of why there's a different behavior on the different platforms (Windows 7 and Mac 10.7.5)

thanks!


Kodi

Santosh Reddy
11th February 2013, 21:02
Make sure RAO_Edit is initialized to 0 in the ctor?

amleto
11th February 2013, 21:03
where do you set RAO_Edit = 0 (or NULL)?

If you do not do this, then !RAO_Edit will be true just because RAO_Edit is unitialised and contains junk.

mtnbiker66
11th February 2013, 22:05
(facepalm)

Well, that's embarrassing - I completely forgot to initialize it! It was working on the Mac just by shear luck and probably worked on my Windows machine in the past for the same reason. Thanks for pointing out what should have been dead obvious :)

Kodi

d_stranz
11th February 2013, 22:32
If I had $1 for every time I've pounded my head on the wall trying to figure out unexplained behavior, only to have it turn out to be an uninitialized variable, I wouldn't have to work any more...

mtnbiker66
12th February 2013, 16:22
You'd think after programming for almost 30 years I would have looked for the obvious first!

d_stranz
12th February 2013, 21:02
You'd think after programming for almost 30 years I would have looked for the obvious first!

Ditto. I chalk it up to "early onset old-timer's disorder".

mtnbiker66
13th February 2013, 21:16
Ditto. I chalk it up to "early onset old-timer's disorder".

I chalk it up to 1) being a father of a 20 month old 2) working a second job in the evenings and 3) has a spouse who works from home :) That's also my excuse for the hair graying and falling out, too...