[Qt-interest] Q_ASSERT error/bug in qt_win_display_dc()?

Arnold Krille arnold at arnoldarts.de
Fri Sep 11 16:42:57 CEST 2009


Hi,

On Friday 11 September 2009 16:32:17 Joshua Senecal wrote:
> I'm encountering the following error when debugging some code:
> Q_ASSERT(qApp && qApp->thread() == QThread::currentThread());
> This happens when attempting to draw some text. I don't see why this
> Assert is in there, as it doesn't make much sense to me.
> According to the Qt Task Tracker (tag # 231157) this is (was) to be
> fixed in version 4.5.0. I have version 4.5.0, and it's definitely still
> there:
> Q_GUI_EXPORT HDC qt_win_display_dc()                  // get display DC
> {
>     Q_ASSERT(qApp && qApp->thread() == QThread::currentThread());
>     if (!displayDC)
>         displayDC = GetDC(0);
>     return displayDC;
> }
> Is anyone else encountering this problem? Short of commenting out the
> Assert and recompiling Qt, is there a workaround? I'm guessing not, but
> thought I'd ask.

Looks as if you are trying to draw text outside the main-thread. Which you 
shouldn't do as the qt docs and this mailing-list state over and over again...

By fixing the bug, I don't think they mean to simply remove the assertion and 
hope everything is goes well. Its more a question of not triggering this 
function from outside the main-thread. So if the bug is fixed, they probably 
checked that from within qt this function is only executed in the main-thread. 
Of course they can't check your code.

Well, they can. That is why the assertion is there. In fact I use similar 
assertions when I make sure a function is executed only in the main-thread. Or 
from within the objects thread. Most times I don't assert, but just issue a 
warning and/or add the given arguments to an internal buffer to process the 
data in the correct thread.

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090911/7aade1d8/attachment.bin 


More information about the Qt-interest-old mailing list