Results 1 to 6 of 6

Thread: error: no matching function for call to QtConcurrent::run()

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default error: no matching function for call to QtConcurrent::run()

    Qt Code:
    1. error: no matching function for call to 'run(Widget* const, bool (Widget::*)(bool))'
    2. QFuture<void> future = QtConcurrent::run(this, &Widget::loadMenuItems);
    3. ^
    To copy to clipboard, switch view to plain text mode 

    Defined in header as:
    Qt Code:
    1. bool loadMenuItems(bool reload=false);
    To copy to clipboard, switch view to plain text mode 

    Widget.cpp:
    Qt Code:
    1. Widget::Widget(QWidget *parent) :
    2. QLineEdit(parent)
    3. {
    4.  
    5. QFuture<void> future = QtConcurrent::run(this, &Widget::loadMenuItems);
    6. future.waitForFinished();
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    I am following the example in the docs, but I keep getting this error.

  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: error: no matching function for call to QtConcurrent::run()

    Your loadMenuItems() is a free function not a member of the Widget class, so the second argument makes no sense.
    If you remove the "&Widget::" from the second argument then the first argument makes no sense.
    You are telling QConcurrent::run() that the function returns void when the declaration indicates it returns bool.

    Why you are using a thread here is also not clear, especially since you then block waiting for it to finish. Why not just call loadMenuItems() directly?

  3. #3
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: error: no matching function for call to QtConcurrent::run()

    I forgot to mention that loadMenuItems() is a Widget private method.
    I get the same error if I do
    QFuture<bool> future = QtConcurrent::run(this, &Widget::loadMenuItems);
    And the blocking part is just what came with the example, I intend to remove it.

  4. #4
    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: error: no matching function for call to QtConcurrent::run()

    I forgot to mention that loadMenuItems() is a Widget private method.
    Not if it is defined like your example.

    QtConcurrent does not know about your default parameter, just that the signature is "bool f(bool)" so you must provide a value in your call to QtConcurrent::run(). This, for example, compiles:
    Qt Code:
    1. class Widget: public QWidget {
    2. Q_OBJECT
    3. public:
    4. explicit Widget(QWidget *p = 0): QWidget(p) {
    5. QFuture<bool> future = QtConcurrent::run(this, &Widget::loadMenuItems, true);
    6. }
    7. private:
    8. bool loadMenuItems(bool flag = false) {
    9. return flag;
    10. }
    11. };
    To copy to clipboard, switch view to plain text mode 

    And the blocking part is just what came with the example, I intend to remove it.
    If you do not block at that point then the variable future will go out of scope immediately and you will no have access to the state or return of the thread.

    Your loadMenuItems() function will run in another thread. Be careful if you try to access the parent object, allocate memory you expect to use in the GUI thread, or do things that are only supported in the GUI thread.

  5. #5
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: error: no matching function for call to QtConcurrent::run()

    Ah, I thought it knew about the default value for the parameter, that fixes it.
    My use case is that i have to load many items from a list stored on file, I imagine I can read the file into a QList and then pass it back to the main thread by emitting a signal?

  6. #6
    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: error: no matching function for call to QtConcurrent::run()

    Yes, I guess you can.

Similar Threads

  1. Replies: 2
    Last Post: 10th June 2012, 12:48
  2. error: no matching function for call to ‘QTimer:
    By saman_artorious in forum Qt Programming
    Replies: 2
    Last Post: 21st May 2012, 15:27
  3. about no matching function for call to
    By Alain Delon in forum General Programming
    Replies: 1
    Last Post: 5th March 2011, 21:30
  4. Replies: 1
    Last Post: 1st December 2010, 11:02
  5. No Matching function to call...
    By weepdoo in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2008, 17: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.