Results 1 to 9 of 9

Thread: Buttons

  1. #1
    Join Date
    Apr 2010
    Posts
    17
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Buttons

    Hello,

    i have read few forum on it but i need your help for a little problem :

    i want to put a button on my window,
    i declared my button on the main with :
    QPushButton *bouton = new QPushButton("Connecter",ui->pushButton);
    bouton->setCheckable(true);

    i would like to make an action named "connection" when i click on it. So i connect the button but i don't know what i should write instead of the "???"
    connect(ui->pushButton,SIGNAL(clicked()),????,SLOT(connection ()));

    should i create a new file to put my function into?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Buttons

    first you have to declare connection() as a slot. second, it does not matter where (in which class) you declare that slot, just put a pointer to that class instead of ?????.
    Most likely, you declare that slot in the widget you create your button, then use this for ???.

  3. #3
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Buttons

    1. Is it that you really wanted to put new buttun bouton INSIDE another button ui->pushButton ?
    2. If you have a QAction, named connection, you should do
    Qt Code:
    1. connect(ui->pushButton,SIGNAL(clicked
    2. ()),ui-> connection,SLOT(trigger()));
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Apr 2010
    Posts
    17
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Buttons

    thanks, but i still have a problem ^^

    i declared my function connection as a slot like that in my header :
    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    ....
    public slots :
    void connection();
    ...
    };


    in the .cpp i write that :
    QPushButton *bouton = new QPushButton("Connecter Wiimote",ui->pushButton);
    bouton->setCheckable(true);
    QObject::connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(connection ()));


    my function connection is :
    void MainWindow::connection()
    {
    ...
    }


    There is no errors at the compilation.
    However when i cllick on the button, the code in my function connection is not executed... what's wrong?

  5. #5
    Join Date
    Apr 2010
    Location
    Russia
    Posts
    6
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Buttons

    emmm)
    Write this and all will earn:
    Qt Code:
    1. QObject:: connect (bouton, SIGNAL (clicked(), this, SLOT (connection ()));
    To copy to clipboard, switch view to plain text mode 
    Last edited by Chexov; 19th April 2010 at 10:58.

  6. #6
    Join Date
    Apr 2010
    Posts
    17
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Buttons

    cool! i'm a joke... ^^
    Thanks

  7. The following user says thank you to valy12 for this useful post:

    Chexov (19th April 2010)

  8. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Buttons

    if you use ui you don't have to create a new button. ui->pushButton is already a full button, so there is no need to recreate one. Simply use your
    Qt Code:
    1. QObject::connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(connection()));
    To copy to clipboard, switch view to plain text mode 
    and skip all the
    Qt Code:
    1. QPushButton *bouton = new QPushButton("Connecter Wiimote",ui->pushButton);
    2. bouton->setCheckable(true);
    To copy to clipboard, switch view to plain text mode 
    things...

    Lykurg

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

    Chexov (19th April 2010)

  10. #8
    Join Date
    Apr 2010
    Location
    Russia
    Posts
    6
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Buttons

    Lykurg you are right, but its way is amusing and works)
    valy12 when you add object in gui redactor, it is not obligatory to describe again the button in a code, the nobility its objective name suffices and to address to it it is possible through the index ui)
    Sorry for my english,i am from Russia)

  11. #9
    Join Date
    Apr 2010
    Posts
    17
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Buttons

    You 're right it's better!
    i use c++ and qt since one week so forgive me

    Thanks all

Similar Threads

  1. Blinking Buttons
    By metdos in forum Newbie
    Replies: 7
    Last Post: 22nd July 2009, 15:36
  2. Treeview with buttons
    By galactor88 in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2009, 08:55
  3. Tool Buttons...
    By csvivek in forum Qt Tools
    Replies: 1
    Last Post: 9th May 2008, 07:44
  4. Colored Buttons
    By Walsi in forum Newbie
    Replies: 33
    Last Post: 8th December 2007, 12:58
  5. Several buttons
    By Mariane in forum Newbie
    Replies: 4
    Last Post: 15th March 2006, 20: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.