Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Controlling execution of program/sub windows using button
Forum Updated to NodeBB v4.3 + New Features

Controlling execution of program/sub windows using button

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wasim3s
    wrote on last edited by
    #1

    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????

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        "Segmentation Fault" is always a memory problem,
        you have referenced to a nonexistent variable in this case.
        So create your SessionWindow on the heap.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved