Results 1 to 16 of 16

Thread: QMutex and QDataStream

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default QMutex and QDataStream

    hi
    i need to protect the access of a variable which is currently being filled with the QDataStream(in a multithreading program).

    in the following code does the access of the int variable blocksize is locked or the datastream is locked ,or both.

    QDataStream datastream(socket);
    QMutex mutex;
    mutex.lock();
    datastream >> blocksize;
    mutex.unlock();

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMutex and QDataStream

    None. You don't lock variables.
    The only thing you do here is that you make sure that the code line between lock() and unlock() is not executed by two or more threads at the same time. Nothing more.

  3. #3
    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: QMutex and QDataStream

    Actually even that is not the case here as each thread will have its own mutex instance so they won't be exclusive. The above code is really a no-op (apart from the line operating on the stream).

  4. #4
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QMutex and QDataStream

    thanks for u r replys

    here is my header file.

    //plot.h Include files are not specified to reduce the post size
    Qt Code:
    1. class th : public QThread
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. th();
    7. void run();
    8.  
    9. quint32 blocksize;
    10.  
    11. private slots:
    12. void read_socket();
    13.  
    14. private:
    15. QTcpSocket *socket;
    16. };
    17.  
    18. class PLOT : public QMainWindow
    19. {
    20. Q_OBJECT
    21. public:
    22. PLOT();
    23.  
    24. private:
    25. th t;
    26. };
    27.  
    28. #endif /*PLOT_H_*/
    To copy to clipboard, switch view to plain text mode 

    //plot.cpp
    Qt Code:
    1. th::th() :blocksize(0)
    2. {
    3.  
    4. }
    5.  
    6. void th::run()
    7. {
    8. socket=new QTcpSocket();
    9. socket->connectToHost("192.168.1.6", 9999);
    10. connect(socket, SIGNAL(readyRead()), this, SLOT(read_socket()));
    11. exec();
    12. }
    13.  
    14. void th::read_socket()
    15. {
    16. QDataStream in(socket);
    17. if (blocksize == 0)
    18. {
    19. if (socket->bytesAvailable() < (int)sizeof(quint32))
    20. return;
    21.  
    22. in >> blocksize;
    23. }
    24. }
    25.  
    26. PLOT::PLOT()
    27. {
    28. t.start();
    29.  
    30. //waiting here till the t.blocksize variable is getting filled but had not worked and never
    31. //gets out of the loop,i have tried declaring the blocksize variable in the [B]th[/B]
    32. //class as[B] volatile quint32 blocksize[/B] and even it has not worked.
    33. //only [B]works[/B] when introduce a
    34. //delay here as [B]QTest::qWait(3000);[/B]
    35.  
    36. while (t.blocksize == (qint32)0)
    37. {
    38. qDebug()<<" PLOT inside while "<<t.blocksize;
    39. coloum=(int)(t.blocksize/360);
    40. }
    41. }
    To copy to clipboard, switch view to plain text mode 

    where should i modify the code to work.

  5. #5
    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: QMutex and QDataStream

    Read about QWaitCondition please.

  6. #6
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QMutex and QDataStream

    If i have to use the QWaitCondition i have to use the mutex,which means i need two classes subclassed from QThread , and also i have to do gui in my program.i tried to use QWaitCondition but i am stuck,i am unable to figure where to wait and where to wakeup the thread(one of the class in the above program does not inherit QThread.)

    Do i have to have multiple inheritance(QThread and QWidget ) to solve the above problem in which i have do both gui and threading.


    why the above code never gets out of while.
    here is a sample code
    Qt Code:
    1. #include <QtGui>
    2. #include <QtNetwork>
    3.  
    4. class trd : public QThread
    5. {
    6. public:
    7. void run()
    8. {
    9. while (1)
    10. qDebug()<<"run";
    11. }
    12. };
    13.  
    14. class sub : public QWidget
    15. {
    16. public:
    17. sub()
    18. {
    19. trd th;
    20. th.start();
    21.  
    22. while (1)
    23. qDebug()<<"sub";
    24. }
    25. };
    26.  
    27. int main(int argc, char *argv[])
    28. {
    29. QApplication a(argc, argv);
    30. sub t;
    31. return a.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 

    in this code both the run and sub gets printed alternatively , the same idea i am using to make work in the program(waiting for the while condition to fail) in the above post.where did i made the error.

    thanks
    Last edited by babu198649; 11th April 2008 at 14:14.

  7. #7
    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: QMutex and QDataStream

    I don't really understand what you mean by "where to wait and where to wake"... Don't you know where you want to halt execution of one thread and when to let it run? It is your algoritm - you should know best.

  8. #8
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QMutex and QDataStream

    Consider two classes class GUI(which subclasses QWidget) and class THD(which subclasses QThread) ,now if i want to wait in class G for a condition which is set by class THD ,what should i do.

    here is a simple code what i have explained above.
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class THD : public QThread
    4. {
    5. public:
    6. int i;
    7.  
    8. THD():i(0)
    9. {
    10.  
    11. }
    12.  
    13. void run()
    14. {
    15. i=1;
    16. }
    17. };
    18.  
    19. class GUI : public QWidget
    20. {
    21. public:
    22. GUI()
    23. {
    24. THD th;
    25. th.start();
    26.  
    27. //wait until i is changed and then continue(how to wait)
    28. }
    29. };
    30.  
    31. int main(int argc, char *argv[])
    32. {
    33. QApplication a(argc, argv);
    34. GUI t;
    35. return a.exec();
    36. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    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: QMutex and QDataStream

    Call wait() where you want to wait and wakeAll() where you want to release the other thread. What is the problem?

    Qt Code:
    1. GUI(){THD th; th.start(); wc.wait(&m); }
    2. ...
    3. void run(){ i=0; wc.wakeAll(); }
    To copy to clipboard, switch view to plain text mode 

    By the way, in this case you could easily use signals and slots instead of a mutex...

  10. The following user says thank you to wysota for this useful post:

    babu198649 (11th April 2008)

  11. #10
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QMutex and QDataStream

    thanks wysota
    But the widget is not getting displayed after adding the wc.wait(&m) (i have called show() in main). it seems that it gets stopped until the wc.wakeAll() is called .But i want it to wake according to the buttons pressed in the GUI widget.
    should i have to start the thread in a slot.

    Qt Code:
    1. in this case you could easily use signals and slots instead of a mutex
    To copy to clipboard, switch view to plain text mode 
    the above code is just to explain my problem . i am using the ideas in different program which is large to post here.
    Last edited by babu198649; 11th April 2008 at 15:42.

  12. #11
    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: QMutex and QDataStream

    Quote Originally Posted by babu198649 View Post
    it seems that it gets stopped until the wc.wakeAll() is called
    Isn't that what you wanted? You wanted to stop execution of a thread until a variable is changed in another thread. That's exactly what happens.

    in this case you could easily use signals and slots instead of a mutex
    the above code is just to explain my problem . i am using the ideas in different program which is large to post here.
    Then maybe you should try expressing your problems more clearly. If you describe your problem incorrectly, you can only blame yourself for getting a wrong answer. Without seeing your code I can only say "redesign code to use signals and slots and rely on the event queue for synchronization".

  13. #12
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QMutex and QDataStream

    There is a server and a client program. Server should be started first and when the client gets connected to server, server sends array(floating values) of data through socket

    The first four bytes of the data which is send through socket contains the total number of floating values(size of array).

    here is the server program

    //ss.h server program
    Qt Code:
    1. #ifndef SS_H_
    2. #define SS_H_
    3.  
    4. #include <QtGui>
    5. #include <QtNetwork>
    6.  
    7. class SS:public QWidget
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. SS();
    13.  
    14. private slots:
    15. void send_data();
    16.  
    17. private:
    18. float *val_var;
    19. long val_var_size;
    20. QTcpServer *server;
    21.  
    22. };
    23.  
    24. #endif /*SS_H_*/
    To copy to clipboard, switch view to plain text mode 

    //ss.cpp
    Qt Code:
    1. #include "ss.h"
    2. #include <QtGui>
    3.  
    4. SS::SS()
    5. {
    6. val_var_size=180000;
    7. val_var =new float[val_var_size];
    8. for (long i=0; i<val_var_size; i++)
    9. {
    10. *(val_var+i)=i;
    11. qDebug()<<*(val_var+i);
    12. }
    13.  
    14. //send the data through socket
    15. server =new QTcpServer();
    16. if (!server->listen(QHostAddress::Any, 9999))
    17. {
    18. qDebug()<<"unable to listen to port";
    19. exit(1);
    20. }
    21. else
    22. qDebug()<<"Server is running ,Start the client";
    23.  
    24. connect(server, SIGNAL(newConnection()), this, SLOT(send_data()));
    25. }
    26.  
    27. void SS::send_data()
    28. {
    29. QByteArray block;
    30. QDataStream out(&block, QIODevice::WriteOnly);
    31. out << (quint32)0;
    32.  
    33. for (long i=0; i<val_var_size; i++)
    34. out<<*(val_var+i);
    35.  
    36. //write the size of array in the first 4 bytes of data.
    37. out.device()->seek(0);
    38. out << (quint32)(val_var_size);
    39.  
    40. QTcpSocket *socket = server->nextPendingConnection();
    41. connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
    42. socket->write(block);
    43. socket->disconnectFromHost();
    44. qDebug()<<"ALL data has been send to socket..";
    45. }
    46.  
    47. int main(int argc, char *argv[])
    48. {
    49. QApplication app(argc, argv);
    50. SS s;
    51. return app.exec();
    52. }
    To copy to clipboard, switch view to plain text mode 

    In the client program there is a seperate thread which reads the data from socket and stores in array, where as the main class(ie.class PLOT) reads the data stored in the array and starts to paint on the pixmap based on the array values.

    The thread which works on the socket ,first stores the first four bytes(size of the array) in a variable.
    The main class(ie.class PLOT) needs this value to decide, the number of polygons a circle should be split in to.And then based on the array values the polygons are painted with different colors.
    So main class(ie.class PLOT) has to wait till the thread(th class) stores the first 4 bytes(size of array) .also the events (paint event) should not get blocked(ie.if a widget is created and showed it should get displayed even when the main class(class PLOT) is in wait state)

    the waitconditions examples does array access but does not deal with any gui.



    //plot.h client program
    Qt Code:
    1. #ifndef PLOT_H_
    2. #define PLOT_H_
    3.  
    4. #include <QtGui>
    5. #include <QtNetwork>
    6.  
    7. class th : public QThread
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. th();
    13. void run();
    14.  
    15. float *arr;
    16. quint32 blocksize;
    17. quint32 blocksize_check;
    18.  
    19. private slots:
    20. void read_socket();
    21.  
    22. private:
    23. QTcpSocket *socket;
    24.  
    25. };
    26.  
    27. class PLOT : public QMainWindow
    28. {
    29. Q_OBJECT
    30.  
    31. public:
    32. PLOT();
    33.  
    34. protected:
    35. void paintEvent(QPaintEvent *);
    36. void wheelEvent(QWheelEvent * event);
    37. void mouseMoveEvent(QMouseEvent * event);
    38. void mousePressEvent(QMouseEvent *event);
    39.  
    40. private:
    41. th t;
    42.  
    43. QVector<QPolygonF> pol;
    44. QPixmap pixmap;
    45. QPixmap pixmap_scaled;
    46.  
    47. qreal zoomfactor;
    48.  
    49. QPoint mouse_press;
    50. QPoint offset;
    51. };
    52.  
    53. #endif /*PLOT_H_*/
    To copy to clipboard, switch view to plain text mode 


    //plot.cpp
    Qt Code:
    1. #include "plot.h"
    2. #include <QtTest>
    3. #include <math.h>
    4.  
    5. #include <qwt_color_map.h>
    6. #include <qwt_double_interval.h>
    7.  
    8.  
    9. th::th() :
    10. blocksize(0), blocksize_check(0)
    11. {
    12.  
    13. }
    14.  
    15. void th::run()
    16. {
    17. socket=new QTcpSocket();
    18. socket->connectToHost("127.0.0.1", 9999);
    19. connect(socket, SIGNAL(readyRead()), this, SLOT(read_socket()));
    20. exec();
    21. }
    22.  
    23. void th::read_socket()
    24. {
    25. qDebug()<<"read_socket";
    26. QDataStream in(socket);
    27. if (blocksize == 0)
    28. {
    29. if (socket->bytesAvailable() < (int)sizeof(quint32))
    30. return;
    31.  
    32. in >> blocksize;
    33.  
    34. qDebug()<<"inside if";
    35.  
    36. wc.wakeAll();
    37.  
    38. arr=new float[blocksize];
    39. qDebug()<<" block size "<<blocksize;
    40. }
    41.  
    42. //fill the array which is accessed by the PLOT class later
    43. while (blocksize_check<blocksize)
    44. {
    45. in>>*(arr+blocksize_check);
    46. blocksize_check++;
    47. }
    48. }
    49.  
    50. PLOT::PLOT() :
    51. zoomfactor(1)
    52. {
    53. resize(800, 600);
    54. t.start();
    55.  
    56. offset.setX(0);
    57. offset.setY(0);
    58.  
    59. int degree=360;
    60. int coloum;
    61.  
    62. wc.wait(&m); // replacing with QTest::qWait(5000); makes work
    63. coloum=(int)(t.blocksize/360);
    64.  
    65.  
    66. qDebug()<<" PLOT "<<t.blocksize<<"coloum "<<coloum;
    67.  
    68. while (t.blocksize == (qint32)0)
    69. {
    70. qDebug()<<" PLOT inside while "<<t.blocksize;
    71. coloum=(int)(t.blocksize/360);
    72. }
    73.  
    74. //calculate the polygon points (a circle is split in to (degree*coloum) polygons)
    75. QPointF points[4];
    76. for (int i = 0; i<degree; i++)
    77. {
    78. for (int j=0; j<coloum; j++)
    79. {
    80. points[0].setX(j * cos(i*(3.14/180)));
    81. points[0].setY(j * sin(i*(3.14/180)));
    82.  
    83. points[1].setX((j +1)* cos(i*(3.14/180)));
    84. points[1].setY((j +1)* sin(i*(3.14/180)));
    85.  
    86. points[2].setX((j +1)* cos((i+1)*(3.14/180)));
    87. points[2].setY((j +1)* sin((i+1)*(3.14/180)));
    88.  
    89. points[3].setX((j)* cos((i+1)*(3.14/180)));
    90. points[3].setY((j)* sin((i+1)*(3.14/180)));
    91.  
    92. QVector<QPointF> vecp;
    93. for (int k=0; k<4; k++)
    94. vecp.append(points[k]);
    95.  
    96. QPolygonF polygon(vecp);
    97. pol.append(polygon);
    98. }
    99. }
    100.  
    101. QwtLinearColorMap colorMap(Qt::blue, Qt::red);
    102.  
    103. //find min and max value to set the color value
    104. float min=0, max=0;
    105. for (int i=0; i<(int)t.blocksize; i++)
    106. {
    107. if (*(t.arr+i)>max)
    108. max=*(t.arr+i);
    109. if (*(t.arr+i)<min)
    110. min=*(t.arr+i);
    111. qDebug()<<*(t.arr+i)<<" "<<i;
    112. }
    113. QwtDoubleInterval di(min, max);
    114.  
    115. pixmap = QPixmap(coloum*2, coloum*2);
    116. pixmap.fill(Qt::transparent);
    117. QPainter painter(&pixmap);
    118. painter.setRenderHint(QPainter::Antialiasing, true);
    119. painter.translate(coloum, coloum);
    120.  
    121. for (int i = 0; i<degree; i++)
    122. {
    123. for (int j=0; j<coloum; j++)
    124. {
    125. painter.save();
    126. painter.setBrush(QBrush(colorMap.color(di, *(t.arr +(coloum*i+j)))));
    127. painter.setPen(colorMap.color(di, *(t.arr+(coloum*i+j))));
    128.  
    129. painter.drawPolygon(pol.at(coloum*i+j));
    130. painter.restore();
    131. }
    132. }
    133.  
    134. pixmap_scaled=pixmap.scaled(1*pixmap.size());
    135. }
    136.  
    137. void PLOT::paintEvent(QPaintEvent *)
    138. {
    139. QPainter painter(this);
    140. painter.save();
    141. painter.drawPixmap(offset, pixmap_scaled);
    142.  
    143. painter.restore();
    144. }
    145.  
    146. void PLOT::wheelEvent(QWheelEvent * event)
    147. {
    148. if (event->delta()>0)//if rotated forward delta() gives positive value
    149. zoomfactor=zoomfactor+0.055;
    150. else
    151. zoomfactor=zoomfactor-0.055;
    152.  
    153. QSize oldsize = pixmap_scaled.size();
    154. pixmap_scaled=pixmap.scaled(zoomfactor*pixmap.size());
    155. QSize newsize= pixmap_scaled.size();
    156. QSize tempsize = (oldsize-newsize)/2;
    157.  
    158. offset.setX(offset.x()+tempsize.width());
    159. offset.setY(offset.y()+tempsize.height());
    160.  
    161. update();
    162. }
    163.  
    164. void PLOT::mouseMoveEvent(QMouseEvent * event)
    165. {
    166. offset=event->pos()-mouse_press+offset;
    167. mouse_press=event->pos();
    168.  
    169. update();
    170. }
    171.  
    172. void PLOT::mousePressEvent(QMouseEvent *event)
    173. {
    174. mouse_press=event->pos();
    175. }
    To copy to clipboard, switch view to plain text mode 

    //main.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include "plot.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. PLOT p;
    9. p.show();
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    i have attached the same program with this post.

    Note:The client program uses qwt-5.0.2 and hence it is required to run the application.
    In the server program the values send through socket(array) are read from netcdf files and it requires its own libraries ,That is why i am sending incremental values through the socket.
    Attached Files Attached Files
    Last edited by babu198649; 12th April 2008 at 07:40.

  14. #13
    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: QMutex and QDataStream

    If the gui reacts on the output from the worker thread, then the thread can emit a signal triggering a slot in the gui thread and running your code - no need for any special synchronisation mechanism.

    And by the way, if your thread's only job is to read the network, then get rid of it and do that from the main thread.

  15. #14
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QMutex and QDataStream

    I am unable to explain the problem clearly
    Main class has a worker thread which gets the data from network and puts in array ,while at the same time Main thread uses the data to paint in a pixmap.

    If u help in solving the below program my problem is over.
    the GUI class is put to wait state .On press of the pushbutton the slot in the THREAD class wakes up all the thread.

    please comment the 37th line of code and execute the program ,then a widget is displayed.If it is executed as it is the widget is not displayed.

    the widgets should get displayed even if the 37th line is not commented(ie.even if the program is in wait state.)


    Qt Code:
    1. #include <QtGui>
    2.  
    3.  
    4. class THREAD : public QThread
    5. {
    6. Q_OBJECT
    7.  
    8. public:
    9. void run()
    10. {
    11.  
    12. }
    13.  
    14. public slots:
    15. void slot_run()
    16. {
    17. wc.wakeAll();
    18. qDebug()<<"wakeall..";
    19. }
    20. };
    21.  
    22. class GUI : public QWidget
    23. {
    24. Q_OBJECT
    25.  
    26. public:
    27. THREAD th;
    28. GUI()
    29. {
    30. resize(400,400);
    31. th.start();
    32.  
    33. //only after commenting the below statement(wc.wait(&m)) the widget gets displayed,
    34. //the widget should get displayed even when uncommented.
    35. wc.wait(&m);
    36. qDebug()<<"Wait is over...";
    37.  
    38. QPushButton *button=new QPushButton("click",this);
    39. button->show();
    40.  
    41. connect(button,SIGNAL(clicked()),&th,SLOT(slot_run()));
    42. }
    43. };
    44.  
    45. int main(int argc, char *argv[])
    46. {
    47. QApplication a(argc, argv);
    48. GUI g;
    49. g.show();
    50. return a.exec();
    51. }
    52.  
    53. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  16. #15
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QMutex and QDataStream

    I found the following lines from Qt doc(http://doc.trolltech.com/4.3/threads.html).

    Accessing QObject Subclasses from Other Threads
    QObject and all of its subclasses are not thread-safe.


    also it is said that

    If you are calling a function on an QObject subclass that doesn't live in the current thread and the object might receive events, you must protect all access to your QObject subclass's internal data with a mutex;

    does this mean the code in the above post can never be made work(without using signals and slots).
    Last edited by babu198649; 12th April 2008 at 11:28.

  17. #16
    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: QMutex and QDataStream

    But you are not accessing any QObject from another thread... I think you have to change your way of thinking. Instead of thinking of the application as one linear flow, think of it as a state machine that is driven by the flow of events. Divide your application model into states and observe what needs to be done when changing states. You'll then be able to do everything in a single thread or in multiple threads but without any additional synchronization.

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.