Results 1 to 3 of 3

Thread: Button Return

  1. #1
    Join Date
    Jan 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Button Return

    How can i return any value when i will click to button. It is possible to use QObject::connect(&get, SIGNAL(clicked()), &give, SLOT(return value)?


    Qt Code:
    1. int main(int argc, char *argv[]) {
    2. int a = 10;
    3.  
    4. QApplication app(int argc, char *argv[]);
    5.  
    6. QWidget wid1;
    7. wid1.resize(100, 100);
    8.  
    9. QWidget wid2;
    10. wid2.resize(100,100);
    11.  
    12. QPushButton but1("Text", &wid1);
    13. but1.geometry(0,0,100,100);
    14. QObject::connect(&but1, SIGNAL(clicked()), &wid1, SLOT(>>return value<<));
    15.  
    16. QPushButton but2("Text", &wid2);
    17. but2.geometry(0.0.100.100);
    18. QObject::connect(&but2, SIGNAL(clicked()), &wid1, SLOT(>>return value<<));
    19. }
    To copy to clipboard, switch view to plain text mode 

    (ignore the code errors... i want only know, if i can použÃ*t QObject::connect(&but2, SIGNAL(clicked()), &wid1, SLOT(return a = 50);
    Last edited by lorin; 8th January 2011 at 20:15.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Button Return

    I didn't quite understand what are you trying to achieve...

    So here are some stuff that might (depending on what you want to do) help you:
    You can encapsulate that int a as a member in the same class with your button and the slot, and then connect the clicked() signal with some slot_name() and in that slot:
    1) you can call the other slot_with_int(a) //slots can be called directly just like member functions (because they basically are member functions)
    or
    2) code another signal that has a int parameter and emit the my_signal(a) //of-course in this case you need another slot that will do the work and a connection to it


    Added after 12 minutes:


    Quote Originally Posted by lorin View Post
    QObject::connect(&but2, SIGNAL(clicked()), &wid1, SLOT(return a = 50);
    Yes you can do that, but the connect statement should look like this:
    Qt Code:
    1. connect(&but2, SIGNAL(clicked()), &wid1, SLOT(slot_name() ));
    To copy to clipboard, switch view to plain text mode 

    And slot_name can have a default value:
    Qt Code:
    1. void slot_name(int x = 50)
    To copy to clipboard, switch view to plain text mode 

    Another advice is to use the heap to allocate QWidgets.
    Last edited by Zlatomir; 8th January 2011 at 20:26.

  3. #3
    Join Date
    Jan 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Button Return

    Thanks you a lot!

Similar Threads

  1. Changing text of button in no relation to button
    By Sabre Runner in forum Newbie
    Replies: 22
    Last Post: 23rd September 2010, 13:29
  2. QSqlQuery don't return
    By ShadowBelmolve in forum Newbie
    Replies: 2
    Last Post: 9th September 2010, 21:28
  3. Replies: 6
    Last Post: 21st August 2010, 22:09
  4. Replies: 1
    Last Post: 2nd August 2010, 06:40
  5. Custom widget: a button within a button
    By Gnurou in forum Qt Programming
    Replies: 7
    Last Post: 18th June 2009, 10:03

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.