Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23

Thread: -how to run a function in separate thread

  1. #21
    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: -how to run a function in separate thread

    Quote Originally Posted by shivendra46d View Post
    I am trying on both the version Qt 4 as well as on Qt 5
    In Qt5 your project file needs a "QT += concurrent" line for QtConcurrent to work.

    As for running a function in a thread, if it is a fire-and-forget situation, the two easiest approaches are to use QtConcurrent:run() or QRunnable in case you have problems in assembling a proper direct call to QtConcurrent::run().
    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.


  2. #22
    Join Date
    Dec 2012
    Posts
    45
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: -how to run a function in separate thread

    I tried running in QTConcurrent my function
    void SRP_Ray_Plot(double No_Of_Rays, double Max_Range,double Source_Depth,double Initial_Angle, double Angle_Difference);
    like this
    QFuture<void> future = QtConcurrent::run(SRP_Ray_Plot, number_of_rays, max_range, source_depth,initial_angle,Angle_Difference);
    but it is giving me error

    mainwindow.cpp:1155: error: no matching function for call to `run(<unknown type>, double&, double&, double&, double&, double&)'
    in the include i tried using
    #include<QTConcurent>
    but it shows error no such file or directory
    and when i use
    #include <qtconcurrentrun.h>
    the error about no such file is removed.
    Where i am wrong ?

  3. #23
    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: -how to run a function in separate thread

    Qt Code:
    1. #include <QtConcurrentRun>
    2.  
    3. void SRP_Ray_Plot(double No_Of_Rays, double Max_Range, double Source_Depth, double Initial_Angle, double Angle_Difference) {
    4. Q_UNUSED(No_Of_Rays); Q_UNUSED(Max_Range); Q_UNUSED(Source_Depth); Q_UNUSED(Initial_Angle); Q_UNUSED(Angle_Difference);
    5. }
    6.  
    7. int main() {
    8. QFuture<void> future = QtConcurrent::run(SRP_Ray_Plot, 1, 1, 1, 1, 1);
    9. return 0;
    10. }
    To copy to clipboard, switch view to plain text mode 

    qmake Code:
    1. QT = core
    2. TEMPLATE = app
    3. TARGET = concurrent
    To copy to clipboard, switch view to plain text mode 
    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.


Similar Threads

  1. OpenGL rendering in separate thread, Qt 5.0.1
    By jaf in forum Qt Programming
    Replies: 3
    Last Post: 27th October 2015, 23:03
  2. How to Have a class run in a separate thread.
    By sona1111 in forum Newbie
    Replies: 7
    Last Post: 29th August 2013, 06:44
  3. GUI Updates from separate Thread
    By sa5webber in forum Newbie
    Replies: 5
    Last Post: 16th June 2012, 20:08
  4. Accesing widgets from separate thread
    By msmihai in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2008, 11:48
  5. new QWidget in separate thread
    By magland in forum Qt Programming
    Replies: 15
    Last Post: 7th February 2008, 12:32

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.