Results 1 to 6 of 6

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPushButton if passed by reference to initialize, app crashing on connect stateme

    That doesn't look like something that would compile.

    "pb" is of type QPushButton* but the method return value is of type QToolButton*, so either of the two needs to be changed.

    Adding the button to the layout in there should be OK

    Cheers,
    _

  2. The following user says thank you to anda_skoa for this useful post:

    rawfool (7th March 2014)

  3. #2
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: QPushButton if passed by reference to initialize, app crashing on connect stateme

    Oh sorry for the typo. I meant QToolButton there.
    Thank you.

  4. #3
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QPushButton if passed by reference to initialize, app crashing on connect stateme

    To your code from the first post: You don't pass a QPushButton by reference. You pass "a pointer to QPushButton by value". That's why btn1/2/3/4 doesn't change after calling addButtons - just a copy of that pointer changes.
    The following piece of code might work.
    Qt Code:
    1. void MyWidget::addButtons(QPushButton *&pb, const QString &str)
    2. {
    3. pb = new QPushButton(this);
    4. pb->setCheckable(true);
    5. pb->setStyleSheet(str);
    6. vLyt->addWidget(pb);
    7. }
    To copy to clipboard, switch view to plain text mode 

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.