Results 1 to 8 of 8

Thread: pass data to SLOT

  1. #1
    Join Date
    Mar 2009
    Posts
    34
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default pass data to SLOT

    Hi,

    I would like to pass an additional boolean parameter with the following slot:
    Qt Code:
    1. QObject::connect(fs, SIGNAL(fileChanged(QString)), this, SLOT(readInfo(QString)));
    To copy to clipboard, switch view to plain text mode 

    I saw QSignalMapper might be the the way to go...can you show an example?

    Thanks,
    Surf

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: pass data to SLOT

    From the documentation of QSignalMapper, line 2 of the detailed description (emphasis is mine):
    This class collects a set of parameterless signals, and re-emits them with integer, string or widget parameters corresponding to the object that sent the signal.
    This will not do for your fileChanged(QString) signal.

    You have to implement the solution yourself. Connect fileChanged(QString) to a slot (in some "proxy" QObject) with a QString parameter only, which then emits another signal adding the boolean value you want.

  3. #3
    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: pass data to SLOT

    No, signal mapper does not do this at all.

    It is used for connecting multiple signal sources to the mapper and then the mapper to a slot and have it pass an identifier or data associated with the original sender.

    What is it that you want to achieve?

    Cheers,
    _

  4. #4
    Join Date
    Mar 2009
    Posts
    34
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: pass data to SLOT

    i would like to pass a bool as shown here (written as pseudo like code, since it will not compile):
    Qt Code:
    1. void MainWindow::onReadStdOut() {
    2. bool info = true; // info will be set by another function
    3. QObject::connect(fs, SIGNAL(fileChanged(QString)), this, SLOT(readInfo(info, QString)));
    4. }
    To copy to clipboard, switch view to plain text mode 

    my current solution (which works fine):
    Qt Code:
    1. void MainWindow::onReadStdOut() {
    2. info = true; // info will be set by another function
    3. QObject::connect(fs, SIGNAL(fileChanged(QString)), this, SLOT(readInfo(QString)));
    4. }
    5.  
    6. void MainWindow::readInfo(QString filename) {
    7. // here i can read info, bc its a member variable
    8. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Oct 2009
    Posts
    483
    Thanked 97 Times in 94 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: pass data to SLOT

    I cannot see what is wrong with your current solution. As far as I know, 'info' seems to be a part of the state of MainWindow, just like the background color of the window, for instance. Why should any of them be passed to readInfo() as a parameter?

  6. #6
    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: pass data to SLOT

    Do you want to associate a boolean with the "fs" object?
    And the boolean is changed by some other code during runtime?

    Cheers,
    _

  7. #7
    Join Date
    Mar 2009
    Posts
    34
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: pass data to SLOT

    the bool is changed by information from ReadStdOut...

  8. #8
    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: pass data to SLOT

    If the data is not associated with the "fs" object, then a member variable is definitely the way to go.

    Btw, onReadStdOut() sounds like a slot, be sure you really want to do the connect() in there, i.e. every time the slot is invoked.

    Cheers,
    _

Similar Threads

  1. Pass string to print slot (QPrintPreviewDialog)
    By Rafaelpsmed in forum Newbie
    Replies: 1
    Last Post: 11th February 2015, 08:04
  2. Replies: 3
    Last Post: 25th October 2013, 10:39
  3. Can I pass a default value to a slot?
    By ricardo in forum Qt Programming
    Replies: 4
    Last Post: 8th January 2010, 15:53
  4. Replies: 4
    Last Post: 3rd May 2009, 18:32
  5. Replies: 2
    Last Post: 16th August 2007, 00:20

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.