Results 1 to 6 of 6

Thread: QPushButton if passed by reference to initialize, app crashing on connect statement

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default QPushButton if passed by reference to initialize, app crashing on connect statement

    I have written a function which takes argument as QPushButton pointer, to initialize and apply stylesheet. And later wrote connect statements for the corresponding buttons. On running the application, it is crashing at connect statement. On debugging it's showing segmentation fault. If I comment the connect statements the application runs fine.

    If I can see the buttons laid out & also styles applied to them, then why is it giving the segmentation fault error which resembles for unallocated pointers ?
    Qt Code:
    1. MyWidget::MyWidget(QWidget * parent)
    2. : QWidget(parent)
    3. {
    4. vLyt = new QVBoxlayout;
    5. this->setLayout(vLyt);
    6. addButtons(btn1, "background: green");
    7. addButtons(btn2, "background: white");
    8. addButtons(btn3, "background: black");
    9. addButtons(btn4, "background: blue");
    10.  
    11. connect(btn1, SIGNAL(clicked(bool)), this, SLOT(mySlot1(bool))); // <<--- In debug mode, it's crashing here
    12. connect(btn2, SIGNAL(clicked(bool)), this, SLOT(mySlot2(bool)));
    13. connect(btn3, SIGNAL(clicked(bool)), this, SLOT(mySlot3(bool)));
    14. connect(btn4, SIGNAL(clicked(bool)), this, SLOT(mySlot4(bool)));
    15. }
    16.  
    17. void MyWidget::addButtons(QPushButton * pb, QString str)
    18. {
    19. pb = new QPushButton;
    20. pb->setCheckable(true);
    21. pb->setStyleSheet(str);
    22. vLyt->addWidget(pb);
    23. }
    To copy to clipboard, switch view to plain text mode 

    Why does the application crash at connect statement ?
    Last edited by rawfool; 6th March 2014 at 09:32.

Similar Threads

  1. reference to connect is ambiguous QQuickItem QMainWindow QCustomPlot
    By TheIndependentAquarius in forum Qt Quick
    Replies: 2
    Last Post: 29th January 2014, 14:04
  2. Replies: 1
    Last Post: 22nd August 2013, 16:49
  3. Connect statement problem
    By Bender_Rodriguez in forum Newbie
    Replies: 4
    Last Post: 14th April 2013, 20:34
  4. Replies: 2
    Last Post: 9th May 2011, 10:38
  5. Slots & Signals w/ parameters passed by reference.
    By Wazman in forum Qt Programming
    Replies: 7
    Last Post: 20th December 2008, 00:13

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
  •  
Qt is a trademark of The Qt Company.