Results 1 to 3 of 3

Thread: QTextCharFormat and QVariant

  1. #1
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTextCharFormat and QVariant

    According to the docs, it should be possible to write custom types to a QVariant and to read them from it. As QSettings supports QVariant it implicitly means that you can write custom types to QSettings and get them back. Nice theory but does it work? I tried with QTextCharFormat (declaring the metatype, registering it and registering stream operators) : segfault when reading the QSettings previusly written. I tried the same thing with QTextFormat (base class of QTexCharFormat, which has operators defined) : segfault at the same place... However, when I tried to save/reload QTextCharFormat objects using a QDataStream, everything went fine... Is it me or is QSettings badly broken???

    P.S : I'm using Qt 4.2.2
    Last edited by fullmetalcoder; 15th May 2007 at 20:58.
    Current Qt projects : QCodeEdit, RotiDeCode

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextCharFormat and QVariant

    What does it segfault on? Can you provide a minimal compilable example reproducing the problem?

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTextCharFormat and QVariant

    Quote Originally Posted by wysota View Post
    What does it segfault on?
    Some internal stream function (datastream >> QTextFormat I guess).

    Can you provide a minimal compilable example reproducing the problem?
    Sure! Here it comes :
    Qt Code:
    1. #include <QSettings>
    2. #include <QTextCharFormat>
    3.  
    4. Q_DECLARE_METATYPE(QTextFormat)
    5.  
    6. int main(int argc, char **argv)
    7. {
    8. qRegisterMetaType<QTextFormat>("QTextFormat");
    9. qRegisterMetaTypeStreamOperators<QTextFormat>("QTextFormat");
    10.  
    11. QSettings s("formats.ini", QSettings::IniFormat);
    12.  
    13. s.setValue("normal", f);
    14.  
    15. f.setForeground(Qt::red);
    16. s.setValue("text", f);
    17.  
    18. f.setFontItalic(true);
    19. f.setForeground(Qt::darkBlue);
    20. s.setValue("comment", f);
    21.  
    22. f.setForeground(Qt::lightGray);
    23. s.setValue("doxygen", f);
    24.  
    25. f.setForeground(Qt::black);
    26. f.setFontWeight(10);
    27. f.setFontItalic(false);
    28. s.setValue("text", f);
    29.  
    30. s.sync();
    31.  
    32. foreach ( const QString& key, s.allKeys() )
    33. f = qvariant_cast<QTextFormat>(s.value(key)).toCharFormat();
    34.  
    35. return 0;
    36. }
    To copy to clipboard, switch view to plain text mode 
    Current Qt projects : QCodeEdit, RotiDeCode

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.