Results 1 to 5 of 5

Thread: Signal/Slot question

  1. #1

    Default Signal/Slot question

    Hello,

    I've got a button, which when clicked invokes a slot of another widget. The problem is I need to transfer data (date value), which clicked() does not understand/know. Do I really need to implement a custom button to be able to transfer data? How would you solve this problem?

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal/Slot question

    This is really a C++ issue and not a Qt one. There are numerous ways of sharing data within objects. Without knowing your concrete use-case it is hard to suggest anything.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Default Re: Signal/Slot question

    Hope this makes it clearer:

    connect(ui.pushButton, SIGNAL(clicked()), myGraph, SLOT(nextDay(QEdit))); //QEdit is the currently selected date

  4. #4
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Signal/Slot question

    IMHO the best way to do it is catch signal from button by MainWidow (I assume that this is your window widget), and this slot invoke a custom signal which will fit to your requirements or simply call this method (best approach depends on how you designed your code). Direct connection is impossible in this case.


    Added after 11 minutes:


    Example of slot:
    Qt Code:
    1. void MainWindow::pushButton_clicked()
    2. {
    3. QDate date(QDate::fromString(ui.edit->text()));
    4. if (date.isValid()) {
    5. emit dateHasBeenSelected(date);
    6. } else {
    7. ui.edit->setText(QDate::currentDate().toString());
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by MarekR22; 4th May 2011 at 11:29.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal/Slot question

    myGraph should have a pointer to the object carrying the date and when it receives the clicked() signal from the button, it should query the object for the date and use it according to its needs. You don't need any extra slots here.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. a question about signal and slot
    By jiaorenjie in forum Qt Programming
    Replies: 1
    Last Post: 22nd March 2011, 08:10
  2. Signal Slot Question
    By graciano in forum Newbie
    Replies: 8
    Last Post: 19th August 2009, 10:35
  3. simple question:the slot and signal of QTreeWidget
    By weixj2003ld in forum Qt Programming
    Replies: 3
    Last Post: 21st April 2009, 05:27
  4. Another signal and slot question
    By fnmblot in forum Newbie
    Replies: 5
    Last Post: 4th March 2008, 19:50
  5. QTableWidget signal/slot question
    By twells55555 in forum Qt Programming
    Replies: 8
    Last Post: 6th August 2007, 21:58

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.