Results 1 to 6 of 6

Thread: QtConcurrent question

  1. #1
    Join Date
    Mar 2009
    Location
    Saint Petersburg, Russia
    Posts
    8
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question QtConcurrent question

    I am writing a program which performs some heavy calculations, so I'm exploring QtConcurrent. I've looked at the QtConcurrent Progress Dialog Example and tried to use QtConcurrent::map() in the same way. Here is my code:
    Qt Code:
    1. void MainWindow::some_member_function()
    2. {
    3. ...
    4. QVector<int> vector;
    5. int iterations=int(Ntotal/1000000)+1;
    6. for (int i = 0; i < iterations; ++i)
    7. vector.append(i);
    8. ...
    9. futureWatcher.setFuture(QtConcurrent::map(vector, cycle)); // <----- error
    10. ...
    11. }
    12. void MainWindow::cycle(int &start)
    13. {
    14. //lots of calculations
    15. ...
    16. }
    To copy to clipboard, switch view to plain text mode 
    I'm getting this error:
    mainwindow.cpp:345: error: argument of type `void (MainWindow::)(int&)' does not match `void (MainWindow::*)(int&)'
    I'm confused. How should I use my member function cycle() in QtConcurrent::map() properly?

  2. #2
    Join Date
    Mar 2009
    Location
    Saint Petersburg, Russia
    Posts
    8
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtConcurrent question

    Ok, now I see it was a stupid C++ question, sorry. Solved the problem by making cycle and member variables it uses static. Now everything seems to work, I've got 4x speedup.

  3. #3
    Join Date
    Mar 2009
    Location
    Saint Petersburg, Russia
    Posts
    8
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtConcurrent question

    Things turn out to be not so easy. Yes, I've got 4x speedup, but cycle() function generates huge amount of data (hundreds of megabytes) which should be written to a file, but my attempts to write output data from that function have no success. In my MainWindow class I have static QDataStream member out, and I'm using it for output. During execution there is a lot of qDebug messages "QIODevice::write: ReadOnly device", and output file remains absolutely empty, though if I write something to out before QtConcurrent::map() is started, it is written to a file without problems.
    As far as I understand, multiple threads generated by QtConcurrent::map() somehow automatically lock out and prevent each other from writing to it. Or may be I am wrong? Anyway, what could be done to avoid this?

    Please give me a hint, I'm stuck and this thing is starting to drive me crazy...

  4. #4
    Join Date
    Mar 2009
    Location
    Saint Petersburg, Russia
    Posts
    8
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtConcurrent question

    Any suggestion would be appreciated. Even something like "RTFM".

  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: QtConcurrent question

    You can't access a QIODevice from multiple threads at once, that's for sure. Try returning the data from calculations to the main thread and then writing it sequentially from there.
    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.


  6. The following user says thank you to wysota for this useful post:

    bair (24th March 2009)

  7. #6
    Join Date
    Mar 2009
    Location
    Saint Petersburg, Russia
    Posts
    8
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtConcurrent question

    Thank you very much. I was thinking about returning data from the calculations to the main thread, but the problem is that there's too much data to handle, so I was afraid that memory consumption will be unacceptably high. Now I think I'll manage it.

    Thanks again, you saved me from many hours of attempts to walk through a brick wall.

Similar Threads

  1. QtConcurrent Performance
    By tomf in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2008, 15:41
  2. Exceptions / setjmp/longjmp question
    By Aceman2000 in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2008, 17:14
  3. Question regarding how to paint after zoom.
    By JonathanForQT4 in forum Qt Programming
    Replies: 2
    Last Post: 26th January 2007, 15:34
  4. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 14:38

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.