PDA

View Full Version : Previous frame inner to this frame(corrupt stack?)



coralbird
28th April 2006, 08:32
I am building a c/s system,but now I am runing into the trouble as title.
when client process receive a message from server process,it show a modeless dialog,and when user click close button, it hide the dialog.

at first everything is ok,and then the client process is crashed. gdb shows
the error as title.


below is my way how to realize this.


class ApplicationWindow:: public QMainWindow
{
....
protected:

CControlDlg m_controlDlg; //inherit from QDialog,and I pass this to it as it's parent window in ApplicationWindow's Construct function
}


display the dialog:
ApplicationWindow::showControlDlg()
{
m_control.show()
}

hide the dialog:

CControlDlg::closeEvent(QCloseEvent* e)
{
this->hide();
}

thanks anyone who can give me some idea!

zlatko
28th April 2006, 09:07
Where actually you have crash?
In calling hide() method?

coralbird
28th April 2006, 09:58
Where actually you have crash?
In calling hide() method?


In calling show() method. :mad:

zlatko
28th April 2006, 10:09
Hm then show ApplicationWindow's Construct function

wysota
28th April 2006, 10:16
CControlDlg::closeEvent(QCloseEvent* e)
{
this->hide();
}

Won't it make an infinite loop?

coralbird
28th April 2006, 10:25
Hm then show ApplicationWindow's Construct function
ApplicationWindow::ApplicationWindow()
: QMainWindow( 0, "HMI", estructiveClose|Qt::WStyle_Customize) ,m_controlExecDlg(this)

coralbird
28th April 2006, 10:27
CControlDlg::closeEvent(QCloseEvent* e)
{
this->hide();
}

Won't it make an infinite loop?

it will not,i tested as below:
CControlDlg::closeEvent(QCloseEvent* e)
{
Q_ASSERT(FALSE),
this->hide();
}

Q_ASSERT(FALSE) only execute once.

zlatko
28th April 2006, 10:34
...,m_controlExecDlg(this) what is this? You try init your dialog as app window :eek:

Try next code


class ApplicationWindow:: public QMainWindow
{
....
protected:
CControlDlg *m_controlDlg; //inherit from QDialog,and I pass this to it as it's parent window in ApplicationWindow's Construct function
}

ApplicationWindow::ApplicationWindow(): QMainWindow( 0, "HMI", estructiveClose|Qt::WStyle_Customize)
{
m_controlDlg = new CControlDlg(this);
}

coralbird
28th April 2006, 10:56
...,m_controlExecDlg(this) what is this? You try init your dialog as app window :eek:

Try next code


class ApplicationWindow:: public QMainWindow
{
....
protected:
CControlDlg *m_controlDlg; //inherit from QDialog,and I pass this to it as it's parent window in ApplicationWindow's Construct function
}

ApplicationWindow::ApplicationWindow(): QMainWindow( 0, "HMI", estructiveClose|Qt::WStyle_Customize)
{
m_controlDlg = new CControlDlg(this);
}


It still does not work.:mad:

coralbird
28th April 2006, 11:28
by the way,I pass ApplicationWindow's pointer to a QThread object, and in QThread::run() calls ApplicationWindow::ShowControlDlg().

zlatko
28th April 2006, 11:51
and what is the result? :)

wysota
28th April 2006, 12:04
1. Try to clean your object code (make clean) and build it again.
2. Don't access GUI functions from within threads. It's forbidden :)

coralbird
28th April 2006, 12:27
and what is the result? :)



result is can show dialog successful serval times .

coralbird
28th April 2006, 12:29
1. Try to clean your object code (make clean) and build it again.
2. Don't access GUI functions from within threads. It's forbidden :)

even hide() and show()?I can do it in MFC.

wysota
28th April 2006, 12:58
even hide() and show()?
Yes.

I can do it in MFC.
This is not MFC. GUI operations are not thread safe (especially in Qt3). Use custom events to post a proper event to the main thread instead.
In your case this is probably as simple as
QApplication::postEvent(mywindow, new QShowEvent());.

BTW. Does it make sense to issue "hide()" from within closeEvent? What do you need it for? close event hides the widget by itself... Just remember to call its base class implementation.

coralbird
28th April 2006, 13:20
GUI operations are not thread safe (especially in Qt3). Use custom events to post a proper event to the main thread instead.
In your case this is probably as simple as
QApplication::postEvent(mywindow, new QShowEvent());.

wysota tell me the key.I have tried signal/slot ,and it does not work too.



BTW. Does it make sense to issue "hide()" from within closeEvent? What do you need it for? close event hides the widget by itself... Just remember to call its base class implementation.

I want the dialog is valid all along, maybe I make a mistake here.:p


Great thanks to wysota and zlatko!:rolleyes: :D

wysota
28th April 2006, 14:02
You should probably read this:
http://doc.trolltech.com/3.3/threads.html

Note: You can't use signals across threads in Qt3. It's possible in Qt4, though.

coralbird
29th April 2006, 02:42
You should probably read this:
http://doc.trolltech.com/3.3/threads.html

Note: You can't use signals across threads in Qt3. It's possible in Qt4, though.


sure ,it's is very important.and now i am reading it.