[Qt-interest] How to fix the crash problem when using QGraphicsView on QMainWindow with QLineEdit
Steven Chang
steven01 at ms3.hinet.net
Wed May 5 16:44:52 CEST 2010
Dear Alex,
Thanks a lot for your kindly helps.
It works and never crashes again.
Best Regards,
Steven
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Malyushytsky, Alex
Sent: Wednesday, May 05, 2010 3:18 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] How to fix the crash problem when using QGraphicsView on QMainWindow with QLineEdit
1. First I would highly recommend change allocation of the all QObjects derived classes which might have parent or may be re-parented.
Otherwise parent will attempt to delete it child.
For example:
It looks like that you are trying to show MainWindow in the QGraphicsScene (I would expect to see QGraphicsView in MainWindow), so replace
"MainWindow w;" with "MainWindow* w = new MainWindow;" ,
gView.setScene(&gScene); // will reparent gScene to QGraphicsView gView;
Due to code above you have to replace QGraphicsScene gScene; with a code which allows gView delete gScene when it is destroyed:
QGraphicsScene* gScene = new QGraphicsScene();
All above may not solve your current problems but sure will cause problem later. Your application mostly likely will always crash on exit.
2. I highly recommend to play with Qt Designer constructing QMainWindow and other widgets, inspecting the code it generates at least for purpose of learning.
I don't think code you wrote in MainWindow should cause crash, but it does not make any sense either.
I would recommend you to fix the problem I mentioned above first.
If your main routine can be modified as below it should work.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsScene* gScene= new QGraphicsScene();
tst* w = new tst();
gScene->addWidget( w );
QGraphicsView gView;
gView.setScene(gScene);
gView.adjustSize();
gView.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
Hope this helps,
Alex
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Steven Chang
Sent: Tuesday, May 04, 2010 10:27 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] How to fix the crash problem when using QGraphicsView on QMainWindow with QLineEdit
Dear Sir,
I created a QLineEdit in QMainWindow class as below:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
lineEdit = new QLineEdit(this);
}
Then I created a QGraphicsView and QGraphicsScene in main.cpp and set
MainWindow as the view widget.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QGraphicsScene gScene;
gScene.addWidget(&w);
QGraphicsView gView;
gView.setScene(&gScene);
gView.adjustSize();
gView.show();
return a.exec();
}
But after built the App and executed it, the App would crash if I type any
character in lineEdit.
How do I fix this problem?
Best Regards,
Steven
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.
“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”
“Please consider our environment before printing this email.”
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list