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;; //main client window
    ConnWindow cW; //sub windows;
    if( cW.exec() != 0 )
    SessionWindow y( cW.getSimpleNet() );;
    return a.exec();@

    But when i try to control sub windows with button in "mainwindow" class
    void mainwindow::xyz()
    ConnWindow cW; //sub window;
    if( cW.exec() != 0 )
    SessionWindow y( cW.getSimpleNet() );//sub window;
    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. 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.