Results 1 to 3 of 3

Thread: Multiple calls which create multiple instances of QSignalMapper

  1. #1
    Join Date
    Oct 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Multiple calls which create multiple instances of QSignalMapper

    The Open() function will be initiate a number of times based on user's preference.
    I learned that QSignalMapper will be clear by it's parent upon the destruction of application.
    But what would happened in this case?

    Below are the code snippet:

    Qt Code:
    1. void class1::Open()
    2. {
    3. // opened a folder & and extract a list of directories ...
    4.  
    5. QSignalMapper *signalMapper = new QSignalMapper(this);
    6. for(int i = 0; i < directoryList.size(); i++)
    7. {
    8. std::cout << directoryList[i].toStdString() << std::endl;
    9.  
    10. DirWidget *dirWidgetPtr = new DirWidget(directoryList[i]);
    11. signalMapper->setMapping(dirWidgetPtr->_buttonPtr, directoryList[i]);
    12. connect(dirWidgetPtr->_buttonPtr, SIGNAL(clicked()), signalMapper, SLOT(map()));
    13. _flowLayoutPtr->addWidget(dirWidgetPtr);
    14.  
    15. }
    16. connect(signalMapper, SIGNAL(mapped(QString)), this, SLOT(GetDir(QString)));
    17. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Multiple calls which create multiple instances of QSignalMapper

    But what would happened in this case?
    What would happen to what? The QSignalMapper(s) you create will be destroyed when their parent instance of class1 is destroyed. The DirWidgets will be destroyed when their _flowLayout is destroyed (assuming it is a well behaved QLayout derivative).

  3. #3
    Join Date
    Oct 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Multiple calls which create multiple instances of QSignalMapper

    Thanks for the reply ChrisW67.

    To be specific:
    So is that means class1 keeps all the created QSignalMapper instances until it destroyed?
    Or it destroy the previous one right after I initiate a new QSignalMapper?

Similar Threads

  1. Multiple instances of QWebView
    By darious in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2011, 07:55
  2. Replies: 6
    Last Post: 1st July 2010, 12:02
  3. Replies: 1
    Last Post: 30th December 2008, 13:28
  4. Replies: 1
    Last Post: 1st February 2008, 18:55
  5. Multiple program instances
    By scwizard in forum Qt Programming
    Replies: 13
    Last Post: 1st April 2007, 17:42

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.