0

I am running a thread, but sometimes the program dies. I hope you could tell me why that exit. Error

glibc detected /home/hsr/CMBU-build-desktop-Qt_4_8_1_in_PATH__System__Release/CMBU: corrupted double-linked list: 0x00000000026192e0

Backtrace:

00400000-00437000 r-xp 00000000 08:01 2499001 /home/hsr/CMBU-build-desktop-Qt_4_8_1_in_PATH__System__Release/CMBU
00636000-00637000 r--p 00036000 08:01 2499001 /home/hsr/CMBU-build-desktop-Qt_4_8_1_in_PATH__System__Release/CMBU
00637000-00638000 rw-p 00037000 08:01 2499001 /home/hsr/CMBU-build-desktop-Qt_4_8_1_in_PATH__System__Release/CMBU
02410000-02c5f000 rw-p 00000000 00:00 0 [heap]
7fe2ff74d000-7fe2ffb72000 r--p 00000000 08:01 2755027 /usr/share/fonts/truetype/nanum/NanumGothic.ttf
7fe2ffb72000-7fe300000000 rw-s 00000000 00:04 6717449 /SYSV00000000 (deleted)
7fe300000000-7fe300022000 rw-p 00000000 00:00 0
7fe300022000-7fe304000000 ---p 00000000 00:00 0
7fe304000000-7fe304132000 rw-p 00000000 00:00 0
7fe304132000-7fe308000000 ---p 00000000 00:00 0
7fe308000000-7fe308022000 rw-p 00000000 00:00 0
7fe308022000-7fe30c000000 ---p 00000000 00:00 0
7fe30c26c000-7fe30c2cc000 rw-s 00000000 00:04 6750219 /SYSV00000000 (deleted)
7fe30c2cc000-7fe30c6e4000 r--p 00000000 08:01 2755028 /usr/share/fonts/truetype/nanum/NanumGothicBold.ttf
7fe30c6e4000-7fe30c6e5000 ---p 00000000 00:00 0
7fe30c6e5000-7fe30cee5000 rw-p 00000000 00:00 0

void Thread::run()
{
    while (!stopped) {
        if(messageStr==tr("A")) {
            MainCMBU::ui->dateTimeEdit->setDateTime(QDateTime::currentDateTime());
            msleep(1000);
        }
    }
    //std::cerr << qPrintable(messageStr);
    stopped = false;
}
p.i.g.
  • 2,815
  • 2
  • 24
  • 41
백자현
  • 67
  • 1
  • 9
  • You canot access UI component from another thread. http://stackoverflow.com/questions/10450750/can-you-access-ui-elements-from-another-thread-get-not-set – Ashif Jun 30 '15 at 05:09
  • @Ashif Threading may be the issue, but the linked question is a completely different language and platform. – Retired Ninja Jun 30 '15 at 05:11
  • Try to use QMetaObject::invokeMethod(MainCMBU::ui->dateTimeEdit, "setDateTime", Q_ARG(QDateTime, QDateTime::currentDateTime()); – Yaroslav Jun 30 '15 at 05:13
  • @Yaroslav thank , Is there a difference? what mean? – 백자현 Jun 30 '15 at 05:23

1 Answers1

0
  1. Use a QTimer to update your UI in UI thread
  2. Use that same QTimer to do work, if you plan on doing work
  3. If there is too much work for GUI, use QtConcurrent::run() or similar to do non-GUI work. Use a QFutureWatcher if you need to know when that asynchronous operation is complete.

Sleeping in a thread like you are doing is generally bad design.

In Qt, you cannot access GUI thread elements from non-GUI thread. GUI is NOT threadsafe.

user3427419
  • 1,769
  • 11
  • 15