Results 1 to 8 of 8

Thread: hi,everyone,i have a question about "QButtonGroup"

  1. #1
    Join Date
    Apr 2008
    Posts
    44
    Thanks
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question hi,everyone,i have a question about "QButtonGroup"

    i want to put some QAbstractButtons on the QButtonGroup,and then when one of them is pressed down,the signal"void QButtonGroup::buttonPressed ( QAbstractButton * button ) " is emitted.
    my code:
    Qt Code:
    1. ButtonGroup = new QButtonGroup(this);
    2. QAbstractButton *button1;
    3. button1 = new QAbstractButton(this);
    4. ButtonGroup->addButton(button1);
    To copy to clipboard, switch view to plain text mode 
    there is error like this " cannot allocate an object of abstract type ‘QAbstractButton’"
    it seems that the red color area is wrong

    why? how can i realize the function? May I get the correct code?

    thanks very much for any advices!!
    Last edited by jpn; 29th April 2008 at 08:12. Reason: missing [code] tags

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hi,everyone,i have a question about "QButtonGroup"

    QAbstractButton is an abstract class I guess

    For your code , it should be -

    Qt Code:
    1. ButtonGroup = new QButtonGroup(this);
    2. QPushButton *button1;
    3. button1 = new QPushButton(this);
    4. ButtonGroup->addButton(button1);
    To copy to clipboard, switch view to plain text mode 

    Hope it helps

  3. The following user says thank you to aamer4yu for this useful post:

    to_guliang (20th May 2008)

  4. #3
    Join Date
    Apr 2008
    Posts
    44
    Thanks
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: hi,everyone,i have a question about "QButtonGroup"

    thanks a lot, but the code doesn't work.
    code:
    Qt Code:
    1. QButtonGroup *btnGroup;
    2. btnGroup=new QButtonGroup(this);
    3. QPushButton *button1;
    4. button1 = new QPushButton("LD",this);
    5. btnGroup->addButton(button1,0);
    6. button1->setGeometry(QRect(175,85,45,43));
    7. connect(btnGroup,SIGNAL(ButtonClicked(int)),this,SLOT(show_IL(int)));
    To copy to clipboard, switch view to plain text mode 
    the code in show_IL:
    Qt Code:
    1. if(i == 0)
    2. {
    3. QString str = "LD";
    4. list->addItem(QString(str));
    5. }
    To copy to clipboard, switch view to plain text mode 
    when the button1 is clicked, there is nothing show on my list! the slot doesn't work!

    please help me!
    Last edited by jpn; 29th April 2008 at 08:12. Reason: missing [code] tags

  5. #4
    Join Date
    Jan 2008
    Location
    China
    Posts
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: hi,everyone,i have a question about "QButtonGroup"

    you can connect every button to a signal solely or you should debug the program to see the value of i.

  6. The following user says thank you to songqiming for this useful post:

    to_guliang (20th May 2008)

  7. #5
    Join Date
    Apr 2008
    Posts
    44
    Thanks
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: hi,everyone,i have a question about "QButtonGroup"

    Quote Originally Posted by songqiming View Post
    you can connect every button to a signal solely or you should debug the program to see the value of i.
    i can realize connecting every button to a signal solely. i have 20 buttons, there are so many code to do like that.if i can use ButtonGroup,there will be much easy.
    and i just debug the program to see the value of "i"; it proves that the slot doesn't work.
    how should I do?

  8. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hi,everyone,i have a question about "QButtonGroup"

    u mean the slot is not called ??

    are u using the same line ??
    signal is buttonClicked, not ButtonClicked .... is this the prob ??

  9. The following user says thank you to aamer4yu for this useful post:

    to_guliang (20th May 2008)

  10. #7
    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: hi,everyone,i have a question about "QButtonGroup"

    It's "SIGNAL(buttonClicked(int))" not "SIGNAL(ButtonClicked(int))".
    J-P Nurmi

  11. The following user says thank you to jpn for this useful post:

    to_guliang (20th May 2008)

  12. #8
    Join Date
    Apr 2008
    Posts
    44
    Thanks
    21
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default thanks

    yeah, it's the problem,thanks for everyone
    i'm sorry for delaying reply,i just come back from my vocation

Similar Threads

  1. SQL Question
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 19:36
  2. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 17:49
  3. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34
  4. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 14:38

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.