Results 1 to 9 of 9

Thread: Program crashes when radioButton selected

  1. #1
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Post Program crashes when radioButton selected

    when I click any of the radioButons displayed in my mainWindow... runtime error program crashes(pic att)

    This is my connect statement in constructor of main class
    Qt Code:
    1. connect(ui->radioButton_1, SIGNAL(clicked()), this, SLOT(getInfo()));
    2. connect(ui->radioButton_2, SIGNAL(clicked()), this, SLOT(getInfo()));
    To copy to clipboard, switch view to plain text mode 

    Slot: getInfo
    [code]
    void Dialog::getInfo()
    {
    my_qlabel alpha; // create an instance of class my_qlabel to access public member variables

    if(ui->radioButton_1->isChecked())
    {
    reCounter += 1;
    reX[reCounter] = alpha.x1;
    reY[reCounter] = alpha.y1;
    reO[reCounter] = alpha.theta;
    //ui->radioButton_1->setChecked(false);
    }
    else if ...
    [code]

    Not sure if the connect statement is causing the crash or the if statement

    please help
    Kind Regards

  2. #2
    Join Date
    Nov 2009
    Posts
    39
    Thanks
    9
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes when radioButton selected

    Did you try running in a debugger and printing the stack trace after the crash? Should point you to the offending line...

  3. #3
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes when radioButton selected

    what is the size of reX , reY and reO ?? and what is the initial value of the reCounter

  4. #4
    Join Date
    Sep 2011
    Posts
    1,245
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes when radioButton selected

    are your pointers initialised?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Program crashes when radioButton selected

    Make sure that your GUI is initiated before connect statement.

    Post your class code, there will be some hidden mistakes.

  6. #6
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Question Re: Program crashes when radioButton selected

    Done some modifying on code... to no avail though

    Basically I need to check which radio button selected
    The Problem -> RadioButton in main dialog Class(Window)
    -> the Check statement is in a different class("label class" within Window/dialog)

    Created signals & slots as:
    Qt Code:
    1. Dialog::Dialog(QWidget *parent) :
    2. QDialog(parent),
    3. ui(new Ui::Dialog)
    4. {
    5. ui->setupUi(this);
    6. connect(ui->radioButton_1, SIGNAL(n1_Selected()), my_qlabel, SLOT(my_qlabel::HandleN1()));
    7. connect(ui->radioButton_2, SIGNAL(n2_Selected()), my_qlabel, SLOT(my_qlabel::HandleN2()));
    8. ...
    9. }
    To copy to clipboard, switch view to plain text mode 

    in dialog:
    Qt Code:
    1. void Dialog::on_radioButton_1_clicked()
    2. {
    3. emit n1_Selected();
    4. }
    5.  
    6. void Dialog::on_radioButton_2_clicked()
    7. {
    8. emit n2_Selected();
    9. }
    To copy to clipboard, switch view to plain text mode 

    my slots in sub class (label class)
    .h
    Qt Code:
    1. private slots:
    2. void HandleN1();
    3. void HandleN2();
    To copy to clipboard, switch view to plain text mode 
    .cpp
    Qt Code:
    1. void my_qlabel::HandleN1()
    2. {
    3. //calculations
    4. }
    5.  
    6. void my_qlabel::HandleN2()
    7. {
    8. //diff-calculations
    9. }
    To copy to clipboard, switch view to plain text mode 

    Above not working!
    Where am I going wrong?
    How do I fix it?

    Thanks
    Last edited by ebsaith; 13th June 2013 at 09:18. Reason: updated contents

  7. #7
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Program crashes when radioButton selected

    As i have seen some issues in your code implementation.

    Qt Code:
    1. // Make sure [B]my_qlabel[/B] is is initialized before you use.
    2.  
    3. my_qlabel = new QLabel(this); // my_qlabel is not initialized in your code
    4.  
    5. // ui->radioButton_1 should be 'this' because you are emitting a signal from dialog class
    6. connect(ui->radioButton_1, SIGNAL(n1_Selected()), my_qlabel, SLOT(HandleN1()));
    7.  
    8. // ui->radioButton_2 should be 'this' because you are emitting a signal from dialog class
    9. connect(ui->radioButton_2, SIGNAL(n2_Selected()), my_qlabel, SLOT(HandleN2()));
    To copy to clipboard, switch view to plain text mode 


    Try changing these things...

    CHEERS..!!

  8. The following user says thank you to karankumar1609 for this useful post:

    ebsaith (13th June 2013)

  9. #8
    Join Date
    Jun 2013
    Posts
    58
    Thanks
    26
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Program crashes when radioButton selected

    Thanks, simple as that
    Last edited by ebsaith; 13th June 2013 at 10:40. Reason: updated contents

  10. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,396
    Thanks
    247
    Thanked 691 Times in 681 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Program crashes when radioButton selected

    No, not as simple as that. Do you want to create a *new* QLabel every time a radio button is clicked? That is what is now happening if you modified your code to follow the previous answer. Those new QLabel instances have no relationship at all to any QLabel that might be in your GUI they are simply dangling my_qlabel pointers that will eventually get deleted when the main window goes out of scope.

Similar Threads

  1. Program crashes on 64-bit systems
    By WereWind in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2013, 10:29
  2. Program crashes on OS X Lion
    By fyodor in forum Newbie
    Replies: 1
    Last Post: 31st October 2011, 06:18
  3. Program crashes
    By Fallen_ in forum Qt Programming
    Replies: 49
    Last Post: 20th September 2010, 01:41
  4. Program crashes (SIGSEGV)
    By Voldemort in forum Qt Programming
    Replies: 47
    Last Post: 21st May 2007, 20:09
  5. Replies: 5
    Last Post: 27th May 2006, 13:44

Tags for this Thread

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.