English 中文(简体)
exception generated with qtconcurrent and calling QTime:currentTime
原标题:

I seem to be getting an exception generated only with a thread created with Qtconcurrent::run

I have a class named FPSengine which has a method named FPSengine::getData() that is called by the main thread and 3 other threads (2 QThreads and 1 made with QtConcurrent::run()). Inside FPSengine::getData() I call QTime::currentTime(). If I call FPSengine::getData() from the main thread or one of the QThreads I dont have any problems but when I call FPSengine::getData() from the thread created with Qtconcurrent::run() I sometimes get an exception. Could there be something wrong with Qtconcurrent or QTime:currentTime() or even tzset (which is called by QTime::currentTime from what the gdb stack shows)? Or is there something wrong with my code. Here is the stack info of the failing thread:
0 raise /lib/libc.so.6 0
1 abort /lib/libc.so.6 0
2 ?? /lib/libc.so.6 0
3 ?? /lib/libc.so.6 0
4 free /lib/libc.so.6 0
5 ?? /lib/libc.so.6 0
6 tzset /lib/libc.so.6 0
7 QTime::currentTime() /usr/lib/libQtCore.so.4 0
8 FPSengine::xmitData FPSengine2.cpp 93
9 FPSengine::getData FPSengine2.cpp 21
10 threadDatalog::run threaddatalog.cpp 109
11 ?? /usr/lib/libQtCore.so.4 0
12 start_thread /lib/libpthread.so.0 0
13 clone /lib/libc.so.6 0 14 ?? 0

最佳回答

QTime::currentTime() (or any of the QTime functions, really) are not documented as being concurrent. Also, I doubt that the underlying call (tzset) is designed to handle concurrency very well. Accordingly, you ll probably need to add some protection, such as a mutex, around the call to get the current time to prevent simultaneous access. I don t know if this will solve your issue, but it will probably help.

问题回答

暂无回答




相关问题
Qt: Do events get processed in order?

If I had a class A, where one of its functions does: void A::func() { emit first_signal(); emit second_signal(); } Assuming that a class B has 2 slots, one connected to first_signal, and the ...

How to determine how much free space on a drive in Qt?

I m using Qt and want a platform-independent way of getting the available free disk space. I know in Linux I can use statfs and in Windows I can use GetDiskFreeSpaceEx(). I know boost has a way, ...

Drag & drop with .ui files

I m having big troubles with drag & drop. I ve created a new Qt Designer Form Class in which I have one QListWidget and one QWidget. Now I want to enable dragging & dropping between these two ...

Link errors on Snow Leopard

I creating a small desktop application using Qt and Poco on Mac OS X Snow Leopard. Qt works fine, but once I started linking with Poco I get the following warning: ld: warning: in /Developer/SDKs/...

Showing two windows in Qt4

My friend and I have each created parts of a GUI using Qt 4. They both work independently and I am trying to integrate his form with the my main window. As of now this is the code I am using to try ...

Qt equivalent of .NET data binding?

Is there an equivalent of .NET s data binding in Qt? I want to populate some combo boxes and other widgets with QStrings that refer to specific entities in my database. However, it would be cleaner ...

热门标签