Controlling execution of program/sub windows using button
-
If i run main windows and sub windows from "main". All windows execute normally.
@QApplication a(argc, argv);
mainwindow w;
w.show(); //main client window
ConnWindow cW; //sub windows
cW.show();
if( cW.exec() != 0 )
exit(0);
SessionWindow y( cW.getSimpleNet() );
y.show();
return a.exec();@But when i try to control sub windows with button in "mainwindow" class
@
connect(abc,SIGNAL(clicked()),this,SLOT(xyz()));
void mainwindow::xyz()
{
ConnWindow cW; //sub window
cW.show();
if( cW.exec() != 0 )
exit(0);
SessionWindow y( cW.getSimpleNet() );//sub window
y.show();
}
@
Only ConnWindow execute normally when Sessionwindow try to execute whole program terminate with code 255. While debugger generate "Segmentation Fault"......Kindly help me how to execute sub windows from mainwindow class using button????
-
First: C and C++ code is usually still left aligned. Please edit your post (the link is right to the post under username and avatar) and format it correctly. It's really hard to read that way. If you want others to analyze your code, make it easy for them to read it.
To your actual problem. Nothing that is related to Qt, but due to a lack of understanding of C++. exec() is a blocking call, it will not return until ConnWindow has been closed. Your SessionWindow is created on the stack. y.show() will return immediately and the stack variable holding the SessionWindow is deleted. So there isn't an object anymore that can work. You will have to create SessionWindow on the heap.
-
"Segmentation Fault" is always a memory problem,
you have referenced to a nonexistent variable in this case.
So create your SessionWindow on the heap.