Results 1 to 7 of 7

Thread: The execution get teminate while accessing variable declared in another class

  1. #1
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default The execution get teminate while accessing variable declared in another class

    Hi ,I am using QT 4.4.0 .
    I here attached a sample code where I got a problem. This application consists of two buttons named "Dialog1" and "Dialog2". If we click on "Dialog1" button, a dialog1 will open which consists of one button and If we click on "Dialog2" button, a dialog2 will open which consists of one button .In dialog2 if click I click the button named "Dialog2_Push" I need to get a pop up a message displaying the variable which I had declared in dialog1.h class. I wrote a piece of code for that but the execution stops when I click a button named "Dialog2_Push" which is on dialog2 class dialog.
    So help me or suggest me to access the variable declared in one dialog in another dialog.
    Please go through the attached file.

    With regards,
    Sudheer.
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: The execution get teminate while accessing variable declared in another class

    The parent of dialog2 is not dialog1 but testpro so the following code crashes because "omans" is a null pointer:
    Qt Code:
    1. void dialog2::on_pushButton_clicked()
    2. {
    3. dialog1 *omans = qobject_cast<dialog1 *>(parent());
    4. int dat = omans->datacount;
    5. QMessageBox::information(this,"",""+ QString::number(dat) +"");
    6. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: The execution get teminate while accessing variable declared in another class

    Hi JPN,
    Thanks fro your kind reply.What you have said is right.But I dont know how to over come this problem,I mean I need to access the variable .
    So please suggest me to solve this problem.

    With Regards,
    Sudheer.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: The execution get teminate while accessing variable declared in another class

    You have to change your design. In your current code there is no instance of dialog1 at all when you execute dialog2.
    J-P Nurmi

  5. #5
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: The execution get teminate while accessing variable declared in another class

    Hi JPN,
    thanks for your quick and kind reply.

    You have to change your design. In your current code there is no instance of dialog1 at all when you execute dialog2.
    I didn't get you .If you don't mind please modify the code what I have attached and reply back to me .

    With regards and Thanks,
    Sudheer .

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: The execution get teminate while accessing variable declared in another class

    When "pushButton" is clicked
    1. an instance of dialog1 is created
    2. the event loop of that dialog1 is executed
    3. the execution returns to testpro::on_pushButton_clicked() after the dialog1 event loop exits
    4. dialog1 instance goes out of scope and is automatically destructed according to normal C++ rules

    When "pushButton" is clicked, there is dialog1 but no dialog2.

    And the same goes for "pushButton_2". You create an instance of dialog2 but at that point there is no dialog1.
    J-P Nurmi

  7. #7
    Join Date
    Aug 2008
    Posts
    84
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: The execution get teminate while accessing variable declared in another class

    Hi JPN ,
    thanks for your kind reply.I understood what you have told .Thanks for your explanation ,But how can I over come this problem to implement the same concept.
    So please help me to solve the problem .

Similar Threads

  1. nmake error during .pro compiling
    By mattia in forum Installation and Deployment
    Replies: 5
    Last Post: 18th June 2008, 10:15
  2. Just for fun game
    By vermarajeev in forum Qt-based Software
    Replies: 6
    Last Post: 13th December 2007, 21:52
  3. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49
  4. Accessing to a static variable from the same class
    By xgoan in forum General Programming
    Replies: 6
    Last Post: 5th March 2007, 10:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.