Results 1 to 4 of 4

Thread: Giving reference to QThread

  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Giving reference to QThread

    Hello Friends,

    I try today to give a thread a reference from a std::map. The thread have to fill the map but the run finction say that the reference variable are not declared in that scope ..

    so the constructor looks like this
    Qt Code:
    1. using namespace std;
    2. ....
    3.  
    4. MyThread::MyThread(map <int> &p_Map,
    5. QObject* parent): QThread(parent)
    6. {
    7. }
    8.  
    9. MyThread::run()
    10. {
    11. //using p_Map;
    12. }
    To copy to clipboard, switch view to plain text mode 

    and I try to use it in run()

    is giving a reference to thread not allowed???


    Or what is the best method to fill a map or a vector within a thread????
    Last edited by codeman; 24th March 2010 at 22:02.

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Giving reference to QThread

    ?? You can't access the parameters of one function in another.. You need to store it as a member..

    Qt Code:
    1. class MyThread : ..
    2. {
    3. public:
    4. MyThread(map <int> &p_Map,QObject* parent): QThread(parent)
    5. {
    6. m_data = p_Map;
    7. }
    8. void run()
    9. {
    10. //use m_data ..;
    11. }
    12. private:
    13. map<int>& m_data;
    14. }
    To copy to clipboard, switch view to plain text mode 
    I never tried references in that way.. if it doesn't work just use a pointer to the map.

    HIH

    Johannes

  3. #3
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default Re: Giving reference to QThread

    The point is after the thread is finished I have to use the filled map. With this approach ( I think so ) I loose my map after thread::finished() or??

    The Idea behind this way ( maybe I am unexperienced) I have to fill some data and I don´t want to lock my gui...

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Giving reference to QThread

    No you don't loose it. References and Pointers are not deleted when they go out of scope.

  5. The following user says thank you to JohannesMunk for this useful post:

    codeman (26th March 2010)

Similar Threads

  1. Replies: 2
    Last Post: 5th March 2010, 18:38
  2. giving main window a name?
    By oji in forum Qt Programming
    Replies: 2
    Last Post: 16th November 2009, 11:13
  3. Layout not giving space equally
    By gruszczy in forum Qt Programming
    Replies: 1
    Last Post: 2nd January 2009, 22:49
  4. QFontMetrics not giving proper dimension
    By Gopala Krishna in forum Qt Programming
    Replies: 3
    Last Post: 7th October 2006, 15:00
  5. Suggestions in giving to my application a cool look
    By SkripT in forum Qt Programming
    Replies: 8
    Last Post: 2nd May 2006, 18:30

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.