Page 1 of 2 12 LastLast
Results 1 to 20 of 29

Thread: Data sharing between threads

  1. #1
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Data sharing between threads

    Hello everybody,

    I am new to the qt an now I am trying to write a multithread program. In this program I need to share specific data between the threads. I define these data in a specific class but as I want each elements of this class I recieved the undifined error.

    what should I do?

    Thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Data sharing between threads

    Unless you give us information we cannot help. We have no idea what your code looks like, what the errors are, what you have tried to "fix" it, what this has to do with Qt, what this has to do with threads etc.

  3. #3
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Data sharing between threads

    Thanks ChrisW67,

    first of all I want to know how should I share a specific data such as a data structure or a static array between different threads as a global data. for example I need a buffer which is fill up with one thread and sorted with another thread and showed with a third thread.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Data sharing between threads

    You share the data just like you would in a single thread case, e.g. pass by pointer or reference, have a global variable or accessible through a singleton.
    The only difference is that you need to protect against concurrent access.

    Cheers,
    _

    P.S.: posting to a three year old thread instead of adding information to your new one is going to annoy people, scatter necessary information, increase the time until your problem can be understood

  5. #5
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Data sharing between threads

    Dear anda_skoa,

    thanks for your reply. I am just sharing like in single thread case, defining a new class and in this class I declear my required data as the class members and by creating objects of this class in different threads, shared the data but I face this (error: undefined reference to `Data_Class:rime_rcv_buff_flag')

    this is the class that I share the data with it:
    Qt Code:
    1. #ifndef DATA_CLASS_H
    2. #define DATA_CLASS_H
    3.  
    4. #include <QObject>
    5.  
    6.  
    7. class Data_Class : public QObject
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit Data_Class(QObject *parent = 0);
    12.  
    13. struct A2D_hdr
    14. {
    15. unsigned short PRF_Num;//PRF Number
    16. unsigned short Frame_Num;//Frame Number
    17. unsigned short Video_Length;//video packet total length
    18. unsigned short EOP;//End of packet if all bit set 1
    19. unsigned long rsrvd;//Reserved
    20. };
    21.  
    22. struct DDC_packet
    23. {
    24. struct A2D_hdr DDC_HDR;
    25. unsigned short A2D_Data[700];//1400 byte data
    26.  
    27. };
    28.  
    29. struct MAC_Data_HDR
    30. {
    31. unsigned short CMD;//command
    32. unsigned short Base_Addrs;//Base Address
    33. unsigned short Length;//Length for burst operation in word
    34. };
    35.  
    36. struct MAC_Data
    37. {
    38. struct MAC_Data_HDR total_HDR;
    39.  
    40. struct DDC_packet total_data;
    41.  
    42. };
    43.  
    44. struct PKT_CMPLT_DATA//*************need to add header to it.
    45. {
    46. bool valid;
    47. bool total_set;
    48. bool total_modify;
    49.  
    50. unsigned short arvd_pkts;// for cheking that which has not arrived yet
    51.  
    52. unsigned short prf_num;
    53.  
    54. struct MAC_Data_HDR total_header;//hazf shavad
    55. //struct A2D_hdr cmplt_data_hdr;
    56.  
    57. unsigned char total_hdr[6];
    58. unsigned char A2Dhdr[36];
    59.  
    60. bool part1_set;
    61. bool part1_modified;
    62. struct A2D_hdr cmplt_data_hdr_prt_1;
    63. unsigned short cmplt_data_prt_1[700];//bayad hazf shavad
    64. unsigned char CmpltData_prt_1[1400];
    65.  
    66. bool part2_set;
    67. bool part2_modified;
    68. struct A2D_hdr cmplt_data_hdr_prt_2;
    69. unsigned short cmplt_data_prt_2[700];//bayad hazf shavad
    70. unsigned char CmpltData_prt_2[1400];
    71.  
    72. bool part3_set;
    73. bool part3_modified;
    74. struct A2D_hdr cmplt_data_hdr_prt_3;
    75. unsigned short cmplt_data_prt_3[700];//bayad hazf shavad
    76. unsigned char CmpltData_prt_3[1400];
    77.  
    78. bool part4_set;
    79. bool part4_modified;
    80. struct A2D_hdr cmplt_data_hdr_prt_4;
    81. unsigned short cmplt_data_prt_4[700];//bayad hazf shavad
    82. unsigned char CmpltData_prt_4[1400];
    83.  
    84. bool part5_set;
    85. bool part5_modified;
    86. struct A2D_hdr cmplt_data_hdr_prt_5;
    87. unsigned short cmplt_data_prt_5[700];//bayad hazf shavad
    88. unsigned char CmpltData_prt_5[1400];
    89.  
    90. bool part6_set;
    91. bool part6_modified;
    92. struct A2D_hdr cmplt_data_hdr_prt_6;
    93. unsigned short cmplt_data_prt_6[700];//bayad hazf shavad
    94. unsigned char CmpltData_prt_6[1400];
    95.  
    96. bool part7_set;
    97. bool part7_modified;
    98. struct A2D_hdr cmplt_data_hdr_prt_7;
    99. unsigned short cmplt_data_prt_7[700];//bayad hazf shavad
    100. unsigned char CmpltData_prt_7[1400];
    101.  
    102. };
    103.  
    104.  
    105. struct eth_Header
    106. {
    107. unsigned char dest_addr[6];
    108. unsigned char src_addr[6];
    109. unsigned short lng;
    110.  
    111. struct MAC_Data data;
    112. };
    113.  
    114. //data structure for saving DDC_1 data
    115. static PKT_CMPLT_DATA Q_smpl_pckt_ddc_1[4];
    116. static PKT_CMPLT_DATA I_smpl_pckt_ddc_1[4];
    117. static PKT_CMPLT_DATA Ramp_smpl_pckt_ddc_1[4];
    118. static PKT_CMPLT_DATA Rare_smpl_pckt_ddc_1[4];
    119.  
    120. //data structure for saving DDC_2 data
    121. static PKT_CMPLT_DATA Q_smpl_pckt_ddc_2[4];
    122. static PKT_CMPLT_DATA I_smpl_pckt_ddc_2[4];
    123. static PKT_CMPLT_DATA Ramp_smpl_pckt_ddc_2[4];
    124. static PKT_CMPLT_DATA Rare_smpl_pckt_ddc_2[4];
    125.  
    126. //data structure for sending requsts
    127.  
    128. static eth_Header rqst_pkt;
    129.  
    130. static unsigned char prime_rcv_buff[20][1514];
    131. static bool prime_rcv_buff_flag[20];
    132.  
    133.  
    134. signals:
    135.  
    136. public slots:
    137.  
    138. };
    139.  
    140. #endif // DATA_CLASS_H
    To copy to clipboard, switch view to plain text mode 




    and use it in other threads as below in the header of the thread

    Qt Code:
    1. Data_Class *data_rcv_child;
    To copy to clipboard, switch view to plain text mode 

    and in the .cpp of the thread:
    Qt Code:
    1. Recive_Thread::Recive_Thread(QObject *parent) :
    2. QThread(parent)
    3. {
    4.  
    5. data_rcv_child = new Data_Class(this);
    6. }
    7.  
    8.  
    9. void Recive_Thread::run()
    10. {
    11.  
    12. while(true)
    13. {
    14. .
    15. .
    16. .
    17. memcpy(&data_rcv_child->prime_rcv_buff + prime_rcv_counter, buffer,sizeof(buffer));
    18.  
    19. data_rcv_child->prime_rcv_buff_flag[prime_rcv_counter] = true;
    20.  
    21. .
    22. .
    23.  
    24.  
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 


    and face the error that I mentioned above
    Last edited by havij000; 9th July 2013 at 05:23.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Data sharing between threads

    You have declared that a static array of bools exists. Where and how have you defined that array?

    I really don't think you understand what the storage type of "static" is doing.

  7. #7
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Data sharing between threads

    I defined the static bool array in class Data_Class header. Am I wrong here?

    As I have to check its value in other threads, I declear static type, thus the array keep its last change and I can check it in other threads.

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Data sharing between threads

    No, you declared the array in the Data_Class header. You have declared the static therefore there is only one array shared between all objects of that class (regardless of thread or whether objects of that class exist). Space for the static array is not allocated by creating new instances of Data_Class objects. A cpp source file needs to define the static variable and provide somewhere for the single array to be stored so the linker can connect every attempt to use it to that storage.

    If you are expecting a separate array for each thread then you certainly do not want "static" members.

    This has nothing to do with threads or Qt: it is C++.

  9. #9
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Data sharing between threads

    no I dont want separate array for each thread. the data is the same for all of them and each thread should do one part of the operation on these data.

    My main problem here is that when I want to use any field of the class in each thread I face a the undifine error.
    I need to know the how is the exact way of data sharing between threads?

  10. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Data sharing between threads

    My main problem here is that when I want to use any field of the class in each thread I face a the undifine error.
    Yes, and I have already told you what you need to do to fix it: define the storage for the array.
    In the header
    Qt Code:
    1. class Stuff {
    2. public:
    3. static bool thingies[10]; // this is a declaration that a static array exists.
    4. };
    To copy to clipboard, switch view to plain text mode 
    in a cpp file:
    Qt Code:
    1. bool Stuff::thingies[10]; // this defines where the storage for the static array exists.
    To copy to clipboard, switch view to plain text mode 
    The static storage class has nothing to do with whether the array is accessible from one or more threads and is unnecessary.

    I offer a complete example of a multi threaded Qt program sharing data between threads in the hope of dragging this thread into some relevance to Qt:
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QTimer>
    3. #include <QThread>
    4. #include <QMutex>
    5. #include <QMutexLocker>
    6. #include <QDebug>
    7.  
    8.  
    9. struct Data {
    10. Data(): mutex(new QMutex), value(0) { }
    11. ~Data() { delete mutex; }
    12.  
    13. QMutex *mutex;
    14. int value;
    15. };
    16.  
    17.  
    18. class Writer: public QObject
    19. {
    20. Q_OBJECT
    21. Data *d;
    22. public:
    23. Writer(Data *data, QObject *p = 0):
    24. QObject(p),
    25. d(data)
    26. { }
    27. signals:
    28. void finished();
    29. public slots:
    30. void process() {
    31. QTimer *timer = new QTimer(this);
    32. connect(timer, SIGNAL(timeout()), SLOT(tick()));
    33. timer->setInterval(1000);
    34. timer->start();
    35.  
    36. QTimer::singleShot(8000, this, SIGNAL(finished())); // self-destruct in 8 secs
    37. }
    38.  
    39. void tick() {
    40. qDebug() << "Try writing";
    41. QMutexLocker locker(d->mutex);
    42. d->value++;
    43. qDebug() << "Written" << d->value;
    44. }
    45. };
    46.  
    47. class Reader: public QObject
    48. {
    49. Q_OBJECT
    50. int n;
    51. Data *d;
    52. public:
    53. Reader(int number, Data *data, QObject *p = 0):
    54. QObject(p),
    55. n(number),
    56. d(data)
    57. { }
    58. signals:
    59. void finished();
    60. public slots:
    61. void process() {
    62. QTimer *timer = new QTimer(this);
    63. connect(timer, SIGNAL(timeout()), SLOT(tick()));
    64. timer->setInterval(1000);
    65. timer->start();
    66.  
    67. QTimer::singleShot(10000, this, SIGNAL(finished())); // self-destruct in 10 secs
    68. }
    69.  
    70. void tick() {
    71. qDebug() << n << "Try reading";
    72. QMutexLocker locker(d->mutex);
    73. qDebug() << n << "Read" << d->value;
    74. }
    75. };
    76.  
    77. int main(int argc, char **argv)
    78. {
    79. QCoreApplication app(argc, argv);
    80.  
    81. Data data; // the shared data
    82.  
    83. QThread* thread = new QThread(qApp);
    84. Writer* writer = new Writer(&data);
    85. writer->moveToThread(thread);
    86. QObject::connect(thread, SIGNAL(started()), writer, SLOT(process()));
    87. QObject::connect(writer, SIGNAL(finished()), thread, SLOT(quit()));
    88. QObject::connect(writer, SIGNAL(finished()), writer, SLOT(deleteLater()));
    89. QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    90. thread->start();
    91.  
    92. for (int n = 0; n < 3; ++n) {
    93. thread = new QThread(qApp);
    94. Reader* reader = new Reader(n, &data);
    95. reader->moveToThread(thread);
    96. QObject::connect(thread, SIGNAL(started()), reader, SLOT(process()));
    97. QObject::connect(reader, SIGNAL(finished()), thread, SLOT(quit()));
    98. QObject::connect(reader, SIGNAL(finished()), reader, SLOT(deleteLater()));
    99. QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    100. thread->start();
    101. }
    102.  
    103. return app.exec();
    104. }
    105. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 10th July 2013 at 09:48.

  11. The following 2 users say thank you to ChrisW67 for this useful post:

    anda_skoa (10th July 2013), havij000 (13th July 2013)

  12. #11
    Join Date
    Jul 2013
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Data sharing between threads

    We are trying to study the available item example in one line into another line, and we have a limitation to sustain fixed varying...What is the new update?

  13. #12
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Data sharing between threads

    I used the
    Qt Code:
    1. bool Stuff::thingies[10];
    To copy to clipboard, switch view to plain text mode 
    in the class .cpp file but I face the

    error: invalid use of qualified-name 'Data_Class:: prime_rcv_buff_flag'

  14. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Data sharing between threads

    Paris_Tuileries_Garden_Facepalm_statue.jpg
    That was an example not a cut-n-paste prescription. If you actually put that line in your code it would not be addressing your static member problem and certainly not be generating that error message. Error messages without context are absolutely useless to us.

    It is all academic anyway because you do not need the static storage class to solve the problem. I have already shown a complete example of data shared between threads that I suggest you read.


    Added after 5 minutes:


    Quote Originally Posted by tfgo777 View Post
    We are trying to study the available item example in one line into another line, and we have a limitation to sustain fixed varying...What is the new update?
    Is this a Google Translate (or similar) of a genuine question? It does not seem to have anything to do with this thread.
    Last edited by ChrisW67; 13th July 2013 at 08:03.

  15. #14
    Join Date
    Jul 2013
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Data sharing between threads

    Quote Originally Posted by ChrisW67 View Post
    I offer a complete example of a multi threaded Qt program sharing data between threads in the hope of dragging this thread into some relevance to Qt:
    I had the same problem but your code is a bit complex to me. Here is another solution. Original code and article can be found here.

    Qt Code:
    1. //widget.h
    2. #ifndef WIDGET_H
    3. #define WIDGET_H
    4.  
    5. #include <QWidget>
    6. #include <QThread>
    7. #include <QMutex>
    8.  
    9. struct Shared {
    10. volatile int shared_var;
    11. };
    12.  
    13. class Thread : public QThread
    14. {
    15. Q_OBJECT
    16.  
    17. signals:
    18. void finishProgress(Shared *);
    19. void startProgress();
    20.  
    21. public:
    22. Thread();
    23. void run();
    24.  
    25. private slots:
    26. void on_threadReceived(Shared * main_thread_access);
    27.  
    28. private:
    29. QMutex shared_mutex;
    30. Shared shared;
    31. Shared *main_thread_access;
    32. Shared *worker_thread_access;
    33. };
    34.  
    35. class Widget : public QWidget
    36. {
    37. Q_OBJECT
    38.  
    39. signals:
    40. void sender(Shared *);
    41.  
    42. public:
    43. explicit Widget(QWidget *parent = 0);
    44. ~Widget();
    45.  
    46. private slots:
    47. void on_thread_progressOccured(Shared * worker_thread_access);
    48.  
    49. private:
    50. Ui::Widget *ui;
    51. Thread threadA;
    52. Shared shared;
    53. Shared *main_thread_access;
    54. Shared *worker_thread_access;
    55.  
    56. #endif // WIDGET_H
    57.  
    58. //widget.cpp
    59. #include "widget.h"
    60. #include "ui_widget.h"
    61.  
    62. Widget::Widget(QWidget *parent) :
    63. QWidget(parent),
    64. ui(new Ui::Widget)
    65. {
    66. ui->setupUi(this);
    67. connect(this, SIGNAL(sender(Shared *)), &threadA, SLOT(on_threadReceived(Shared *)), Qt::QueuedConnection); //send shared data to different thread
    68. connect(&threadA, SIGNAL(finishProgress(Shared *)), this, SLOT(on_thread_progressOccured(Shared * )), Qt::QueuedConnection); //receive shared data from different thread
    69. main_thread_access = &shared;
    70. worker_thread_access = NULL;
    71. main_thread_access->shared_var = 2;
    72. }
    73.  
    74.  
    75. //somewhere in the program
    76. emit sender(main_thread_access); //we send a signal which carries the shared data to a different thread
    77.  
    78. void Thread::run() {
    79. worker_thread_access->shared_var += 3; //modify the shared data
    80. shared_mutex.unlock();
    81. emit finishProgress(worker_thread_access);
    82. quit();
    83. }
    84.  
    85. void Widget::on_thread_progressOccured(Shared * worker_thread_access) {
    86. main_thread_access->shared_var = worker_thread_access->shared_var;
    87. if (main_thread_access->shared_var == 2)
    88. QMessageBox::information(this, tr("Error"), tr("Nothing changed on different thread."));
    89. else //if (main_thread_access->shared_var == 3)
    90. QMessageBox::information(this, tr("Ok"), tr("Everything's fine, shared_var == %1.").arg(QString::number(main_thread_access->shared_var)));
    91. //continuous calling of the other thread keeps incrementing the shared data by three.
    92. }
    93.  
    94. void Thread::on_threadReceived(Shared * main_thread_access) {
    95. //qDebug() << "thread start";
    96. shared_mutex.lock(); //Right now I'm not sure about this, maybe a QMutexLocker approach would be better. Or not.
    97. worker_thread_access->shared_var = main_thread_access->shared_var;
    98. //qDebug() << main_thread_access->shared_var;
    99. start(); //we start the other thread here
    100. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by VikMorroHun; 13th July 2013 at 23:56. Reason: spelling corrections

  16. #15
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Data sharing between threads

    one more question, how can I start different threads simultaneously in the ui by clicking a sing bottun?

  17. #16
    Join Date
    Jul 2013
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Data sharing between threads

    Quote Originally Posted by havij000 View Post
    one more question, how can I start different threads simultaneously in the ui by clicking a sing bottun?
    You have to add the necessary yourThread->start() commands or signals to that button's code.

    Quote Originally Posted by VikMorroHun View Post
    I had the same problem but your code is a bit complex to me. Here is another solution. Original code and article can be found here.
    An important thing is missing from the above code, but I can't edit it anymore.

    Thread::Thread() {
    worker_thread_access = &shared;
    }
    Last edited by VikMorroHun; 14th July 2013 at 17:57. Reason: updated contents

  18. #17
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Data sharing between threads

    Oh dear!

    Please people, if you are doing multi thread programming, make sure you have read at least about the basics for that topic.

    The synchronization mechanism, e.g. the QMutex, obviously needs to be along side the shared data. Using different instances a QMutex for a single instance of shared data does not help you in any way.

    It is really very simple:

    1) create a data class that protects its data by using QMutex
    2) create an instance of that data class
    3) pass the data to as many threads as you'd like
    4) start the threads

    Cheers,
    _

  19. #18
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Data sharing between threads

    another question

    how should I set the value of different fields of a data structure that I have defined in the header of my thread class?

    Qt Code:
    1. #ifndef WRT_RQST_THREAD_H
    2. #define WRT_RQST_THREAD_H
    3.  
    4. #include <QThread>
    5. #include "DDC_Header.h"
    6.  
    7. class Wrt_Rqst_Thread : public QThread
    8. {
    9. Q_OBJECT
    10. public:
    11. explicit Wrt_Rqst_Thread(QObject *parent = 0);
    12.  
    13. void run(QString str, int lngth);
    14. bool Stop;
    15.  
    16.  
    17. private:
    18.  
    19. struct wrt_rqst_buff
    20. {
    21. unsigned char Dest_MAC[6];
    22. unsigned char Src_MAC[6];
    23. unsigned char Eth_Length[2];//should be 0x0800
    24. unsigned char Wrt_Cmd[2];//should be 0x0000
    25. unsigned char Base_Addrs[2];
    26. unsigned char Data_Length[2];//should be 0x02EB
    27. unsigned char data[1494];//should be set all az 0
    28.  
    29. }*wrt_buff;
    30.  
    31. signals:
    32.  
    33. public slots:
    34.  
    35. };
    36.  
    37. #endif // WRT_RQST_THREAD_H
    To copy to clipboard, switch view to plain text mode 



    I used
    Qt Code:
    1. *(unsigned short *) wrt_buff->Data_Length = 0x0080;
    To copy to clipboard, switch view to plain text mode 

    but I faced the memory segmentation error.

  20. #19
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Data sharing between threads

    Did you create an instance of the data structure?

    Cheers,
    _

  21. The following user says thank you to anda_skoa for this useful post:

    havij000 (29th July 2013)

  22. #20
    Join Date
    Nov 2012
    Posts
    48
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Data sharing between threads

    How Can I start different threads simultaneously by clicking on a simple buttom?

Similar Threads

  1. Communication/data sharing between threads
    By Tottish in forum Newbie
    Replies: 6
    Last Post: 8th July 2013, 06:33
  2. Threads and Implicit Sharing
    By stillwaiting in forum Newbie
    Replies: 5
    Last Post: 30th November 2010, 16:46
  3. Sharing between two Threads
    By donglebob in forum General Programming
    Replies: 2
    Last Post: 30th October 2008, 08:58
  4. Sharing data between threads
    By bbui210 in forum Qt Programming
    Replies: 15
    Last Post: 19th October 2008, 17:56
  5. Sharing data across threads
    By jphn_crichton in forum Qt Programming
    Replies: 11
    Last Post: 5th May 2008, 18:29

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.