Results 1 to 7 of 7

Thread: Simple question about QtConcurrent

  1. #1
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Simple question about QtConcurrent

    Hi,

    I've the following question:

    Why don't we be able to use a member function jointly with QtConcurrent or QThread? Why must be a standalone function?

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

    It can be a member function as well but it has to be a member function of a class that is carried in the container passed to QtConcurrent. Otherwise than that only static member functions and non-member functions may be used. This is caused by the fact that it is not possible to specify a "pointer to a function of any class" in C++.
    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
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: Simple question about QtConcurrent

    Hi Wysota,

    Thanks a lot, now I understand.

    Bye

  4. #4
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Simple question about QtConcurrent

    I am not sure if I understood the OP's question correctly.

    You can use member functions for some things, e.g. with QtConcurrent::mapped, if you wrap them with Boost.Bind or something similar.

    Example from Qt docs:
    Qt Code:
    1. QList<QImage> images = ...;
    2. QFuture<QImage> thumbnails = QtConcurrent::mapped(images, boost::bind(&QImage::scaledToWidth, 100 Qt::SmoothTransformation));
    To copy to clipboard, switch view to plain text mode 

    HTH

  5. #5
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Simple question about QtConcurrent

    Hi Caduel,

    yes something as:

    class TEST
    {
    public:
    TESTE();

    void funct();
    };

    TESTE test;
    QList<QImage> images = ...;
    QFuture<QImage> thumbnails = QtConcurrent::mapped(images, test.funct(&QImage::scaledToWidth, 100 Qt::SmoothTransformation));

    Now I understand that isn't possible. I must be use static functions for example.
    Like the Wysota explained me

  6. #6
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Simple question about QtConcurrent

    your example is confusing... a function returning void does not make sense with "mapping".

    Qt Code:
    1. class TEST
    2. {
    3. public:
    4. TESTE();
    5.  
    6. QImage funct(const QString&);
    7. };
    8.  
    9. TESTE test;
    10. QLis<QString> files = ...;
    11. QFuture<QImage> pics = QtConcurrent::mapped(files, boost::bind(&TEST::func, &test));
    To copy to clipboard, switch view to plain text mode 
    something like that should work. (Haven't tried it.)

  7. #7
    Join Date
    Jul 2007
    Location
    Jundiai/SP, Brazil
    Posts
    114
    Thanks
    5
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Simple question about QtConcurrent

    Sorry,

    I know about this.
    Your example this ok.


    Thanks for your help

Similar Threads

  1. Simple namespace question
    By JPNaude in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2009, 10:31
  2. QtConcurrent question
    By bair in forum Qt Programming
    Replies: 5
    Last Post: 24th March 2009, 11:46
  3. QTextEdit simple question
    By Marcopolo in forum Qt Tools
    Replies: 4
    Last Post: 11th October 2007, 01:01
  4. simple question on Class-Members
    By mickey in forum General Programming
    Replies: 7
    Last Post: 4th February 2006, 23:37
  5. QTextEdit Qt4: simple question
    By TheKedge in forum Qt Programming
    Replies: 4
    Last Post: 18th January 2006, 13:03

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.