Results 1 to 3 of 3

Thread: Crash caused by QVariant (mis)use

  1. #1
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Crash caused by QVariant (mis)use

    I am using Qt 4.1: In a QTableWidget I am storing a void* pointer as the data for a QTableWidgetItem. As the application is filling the rows (driven from an outside source) I may get a crash resulting from:

    QVariant::compare: type 128 unknown to QVariant. In release mode the program just goes away.

    I am not sure what 'type 128' means with respect to QVariant. Every place I use QVariant with the void*, I use QVariant::UserType ( == 127 ).

    Using the same input, this does not happen every time nor in the same place (possibly a timing thing.) The code driving the input is mature and well tested by other applications so it's clear the error is in my stuff.

    I also get dozens of "QFont: It is not safe to use text and fonts outside the gui thread" debug text, but nowhere in the code is QFont used.

    Qt Code:
    1. // All data is set using Qt::UserRole
    2. Variant v( QVariant::UserType );
    3. v.setValue( pData ); // pData is a void*
    4. item( nRow, nCol )->setData( Qt::UserRole, v );
    5.  
    6. // All data is retrieved using Qt::UserRole
    7. void* pData = item( nRow, nCol )->data( Qt::UserRole ).value<void*>();
    To copy to clipboard, switch view to plain text mode 

    1) Can someone explain the error: QVariant::compare: type 128 unknown to QVariant?

    2) What can cause the QFont message and could this have something to do with the QVariant problem?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Crash caused by QVariant (mis)use

    Quote Originally Posted by mclark View Post
    1) Can someone explain the error: QVariant::compare: type 128 unknown to QVariant?
    Does passing the void* to QVariant::fromValue() give you any better results?
    Qt Code:
    1. QVariant v = QVariant::fromValue(pData);
    To copy to clipboard, switch view to plain text mode 
    It should basically handle a correct type (VoidStar) for you.

    Quote Originally Posted by mclark View Post
    2) What can cause the QFont message and could this have something to do with the QVariant problem?
    Are you using multiple threads in your application? That warning message comes when an instance of QFont is attempted to construct from another thread than the main GUI thread.

    From qfont.cpp:
    Qt Code:
    1. void qt_font_tread_test()
    2. {
    3. if (QApplication::instance() && QThread::currentThread() != QApplication::instance()->thread())
    4. qWarning("QFont: It is not safe to use text and fonts outside the gui thread");
    5. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Crash caused by QVariant (mis)use

    Thanks for your reply.

    After looking over my code it was revealed that I was setting table values from outside the GUI thread. I'm in the process of correcting that now.

    I shall try your QVariant suggestion when the thread issues are fixed.

Similar Threads

  1. Weird crash caused by a QTreeView
    By vfernandez in forum Qt Programming
    Replies: 1
    Last Post: 10th September 2006, 18:31

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.