Results 1 to 2 of 2

Thread: Multi - Thread Programming

  1. #1
    Join Date
    May 2011
    Location
    Indonesia, Surabaya
    Posts
    24
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Multi - Thread Programming

    Hi all!

    i'm working on an webcam video streaming application.. The application has several parts.

    Qt Code:
    1. //Part 1, Frame Grabber
    2. int main(int argc, char **argv)
    3. {
    4. CvCapture *capture;
    5. IplImage *frame;
    6. IplImage *frame1;
    7. IplImage *frame2;
    8.  
    9. double t,ms = 0;
    10. int key = 0;
    11.  
    12. /* Initialize webcam and window */
    13. capture = cvCaptureFromCAM(0);
    14. cvNamedWindow("JCXSUPERTAMARK5",1);
    15.  
    16. while (key != 'q')
    17. {
    18. t = (double)cvGetTickCount();
    19.  
    20.  
    21. /* show the image from webcam */
    22. frame = cvQueryFrame(capture);
    23. cvShowImage("JCXSUPERTAMARK5",frame);
    24. key = cvWaitKey(1);
    25.  
    26. /* converting.. . */
    27.  
    28. frame1 = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
    29. cvCvtColor(frame, frame1, CV_BGR2GRAY);
    30. frame2 = cvCreateImage(cvSize(320,240), IPL_DEPTH_8U, 1);
    31.  
    32. cvResize(frame1,frame2);
    33.  
    34. /* GET ELAPSED TIME */
    35. t = (double)cvGetTickCount() -t;
    36. ms += t / ((double)cvGetTickFrequency() * 1000.0);
    37.  
    38. /* 0.04 sec auto save (25 frame per sec.) */
    39. if (ceil(ms) >= 40)
    40. {
    41. cvSaveImage("test.png",frame2);
    42. ms = 0;
    43. }
    44. }
    45.  
    46. /* free up memory */
    47. cvReleaseCapture(&capture);
    48. cvDestroyWindow("JCXSUPERTAMARK5");
    49.  
    50. return 0;
    51. }
    52.  
    53. //Part 2, image sender
    54. QImage image;
    55. image.load("../appSendImage/test.png", "PNG"); // Prepare / load an image
    56. QString address = "127.0.0.1";
    57. int port = 6667;
    58. SendImage s(address, port); // Construct SendImage and give the server address and port
    59. s.send(image, "test.png");
    To copy to clipboard, switch view to plain text mode 

    And i want these parts to be run in different threads. How can i implement QThread
    in my application ? Need your advice please.. .

    code reference :
    Part 1 :
    http://nashruddin.com/Web_Based_Surv...and_Javascript
    Part 2 :
    http://www.hanckmann.net/?q=node/44

  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: Multi - Thread Programming

    Quote Originally Posted by bajoelkid12 View Post
    How can i implement QThread in my application ?
    What have you already tried to solve your problem?
    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. Qt x11 GUI crash if multi-thread
    By wesley in forum Qt Programming
    Replies: 2
    Last Post: 21st January 2010, 09:11
  2. Multi-thread related problem,help me
    By mendynew in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 03:02
  3. Multi-thread vs. Multicore
    By TheGrimace in forum Qt Programming
    Replies: 10
    Last Post: 20th September 2007, 22:17
  4. Programming client-server with socket in multi-languages
    By philiptine in forum Qt Programming
    Replies: 3
    Last Post: 7th September 2007, 07:35
  5. Multi thread problem
    By sreedhar in forum Qt Programming
    Replies: 5
    Last Post: 26th June 2006, 13:33

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.