Results 1 to 20 of 22

Thread: QThread count in Qt applications.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2010
    Posts
    18
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows

    Default QThread count in Qt applications.

    Hi. For testing i create 1000 threads in my application with QThread class, and all this threads are running. But i get QThread::start: Failed to create thread (The access code is invalid.) this message. What is problem?

    my class is.

    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include "mythread.h"
    3.  
    4. ......int main(int argc, char *argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7.  
    8. QCoreApplication * app = qApp;
    9.  
    10. for (int i=0; i < 1000; i++)
    11. {
    12. MyThread * thread = new MyThread(i, app);
    13. MyThread::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    14. MyThread::connect(thread, SIGNAL(terminated()), thread, SLOT(deleteLater()));
    15. thread->start();
    16. }
    17.  
    18. return a.exec();
    19. }
    20.  
    21. #ifndef MYTHREAD_H
    22. #define MYTHREAD_H
    23. #include <QtCore/QThread>
    24. class MyThread : public QThread
    25. {
    26. Q_OBJECT
    27. public:
    28. explicit MyThread(int number, QObject *parent = 0);
    29. void run();
    30. private:
    31. int number;
    32. signals:
    33. public slots:
    34. };
    35. #endif // MYTHREAD_H
    36. #include "mythread.h"
    37. #include <stdio.h>
    38.  
    39. MyThread::MyThread(int number, QObject *parent) :
    40. QThread(parent), number(number)
    41. {
    42. }
    43.  
    44. void MyThread::run()
    45. {
    46. while (true)
    47. {
    48. //printf("Running thread number: %d\n", number);
    49. QThread::msleep(10000);
    50. }
    51. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 21st October 2010 at 20:28.

Similar Threads

  1. Count files of a directory
    By radu_d in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2012, 03:17
  2. Replies: 0
    Last Post: 17th March 2010, 12:17
  3. Count indexes in QListView
    By been_1990 in forum Qt Programming
    Replies: 5
    Last Post: 17th December 2009, 19:21
  4. Replies: 7
    Last Post: 25th April 2009, 05:13
  5. [QGLWidget] Count FPS
    By Macok in forum Qt Programming
    Replies: 0
    Last Post: 13th April 2009, 14:01

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
  •  
Qt is a trademark of The Qt Company.