Results 1 to 3 of 3

Thread: QVarian::type, QVarian::typeId and QMetaType

  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QVarian::type, QVarian::typeId and QMetaType

    I need to support a codebase for Qt 5.15 LTS and Qt 6.2 LTS.
    One of the last issues is QVariant::type().
    The type of QVariant was deprecated back in 5.x from an enum inside QVariant in favor of QMetaType.
    And for some time now I have been casting the return value to QMetaType for compatibility with Qt 6.0:


    QMetaType::Type t = (QMetaType::Type)myqvariant.type();


    The line above works with 5.15 and 6.0.
    However, Qt 6.3 broke this by removing the method QVariant::type() entirely.
    I now have to use QVariant::typeId(), which is equivalent to QVariant::metaType().id().
    However, neither typeId() nor metaType() exist in 5.15.

    That forces me to litter my code with preprocessor defines to distinguish between 5.15 and 6.3, just to get the type in the same format.

    Is there any way to find a compromise that gets me the type of the QVariant in a way that works with 5.15 and 6.3?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QVarian::type, QVarian::typeId and QMetaType

    That forces me to litter my code with preprocessor defines
    Can you use a C++ macro instead, which has different definitions based on the preprocessor switches? Alternatively, can you define an adapter class or class template that takes a QVariant reference as argument and returns the needed type?

    In either case, the preprocessor switching is hidden away inside the implementation, but it will still require editing all the code that uses it.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    tuli (22nd September 2022)

  4. #3
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QVarian::type, QVarian::typeId and QMetaType

    I will probably have to do that, was hoping I had overlooked a nice way out.
    It's really a shame type() was dropped, especially after compatibility was maintained from 5.x -> 6.0...

Similar Threads

  1. Crash in QQmlValueWrappert::typeId()
    By JanW in forum Qt Quick
    Replies: 0
    Last Post: 15th September 2017, 16:03
  2. Replies: 5
    Last Post: 13th March 2017, 12:51
  3. Replies: 3
    Last Post: 25th June 2015, 11:11
  4. Replies: 5
    Last Post: 22nd February 2013, 14:11
  5. qobject_cast() and typeid() problem
    By codeslicer in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2009, 01:07

Tags for this Thread

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.