Results 1 to 2 of 2

Thread: Static class threading problem

  1. #1
    Join Date
    Jun 2012
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Static class threading problem

    Hello!

    I have a static class that is called upon by other classes to do some processing. I want this function to be static AND in its own thread, so the program doesnt hang when entering the function.

    Now, I read the Qt doc and decided to use QtConcurrent::run, but I get a linker error.

    Here is my code:

    Qt Code:
    1. ImageProcessor.cpp file
    2.  
    3. #include "CustomEvent"
    4. #include <QtConcurrentRun>
    5. #include <QFuture>
    6. #include "ImageProcessor.h"
    7. #include <QSharedPointer>
    8. #include <queue>
    9.  
    10.  
    11. QSharedPointer<CustomEvent> ImageProcessor::Process(QObject *asker, std::queue<Image> images)
    12. {
    13. QMutexLocker locker(m_mutex);
    14.  
    15. extern QSharedPointer<CustomEvent> Calculate(QObject, std::queue<Image>);
    16. QFuture<QSharedPointer<CustomEvent>> future = QtConcurrent::run(Calculate, asker, images);
    17.  
    18. future.waitForFinished();
    19.  
    20. return future.result();
    21. }
    22.  
    23. QSharedPointer<CustomEvent> Calculate(QObject *asker, std::queue<Image> images)
    24. {
    25.  
    26.  
    27. cv::Mat scaleMap;
    28. Image AdditionImage(images.front());
    29.  
    30. images.pop();
    31.  
    32.  
    33. //Dummy while function
    34. while (images.size() != 0)
    35. {
    36. AdditionImage += images.front();
    37. images.pop();
    38. }
    39.  
    40. CustomEvent *processedImage = new CustomEvent(asker, scaleMap);
    41. QSharedPointer<CustomEvent> processedImageSharedPointer(processedImage);
    42.  
    43. return processedImageSharedPointer;
    44. }
    To copy to clipboard, switch view to plain text mode 

    Linker error: Unresolved external symbol in class QSharedPointer<CustomEvent> in class Calculate(...)

    From what I get the extern function does not have access to the inclusions I added at the top of the cpp file?

    Can someone point me to where my error is? Or if there is a better way to code this?

    Thank you!

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Static class threading problem

    You define

    extern QSharedPointer<CustomEvent> Calculate(QObject, std::queue<Image>);

    Why did you use extern? Do you know what it is for?

    Why does it have a different signature to the implementation that you define below,
    QSharedPointer<CustomEvent> Calculate(QObject*, std::queue<Image>);
    ?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Qt Multi Threading RePainting Problem
    By Mohammad in forum Qt Programming
    Replies: 4
    Last Post: 12th January 2012, 16:52
  2. Replies: 1
    Last Post: 17th December 2010, 16:43
  3. accessing static member variables of one class in another class
    By jasonknight in forum General Programming
    Replies: 5
    Last Post: 6th September 2010, 15:53
  4. qt problem with tr() in static member of a class
    By Krzysztow in forum Qt Programming
    Replies: 5
    Last Post: 17th August 2010, 12:29
  5. Is there the static class in C++?
    By gtthang in forum General Programming
    Replies: 4
    Last Post: 25th February 2006, 06:46

Tags for this Thread

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.