Results 1 to 17 of 17

Thread: Qt warning of type conversion already registered

  1. #1
    Join Date
    Nov 2014
    Posts
    6
    Qt products
    Qt4 Qt5

    Default Qt warning of type conversion already registered

    I have a multi-thread Qt program where the Qt sometimes give a warning:

    Qt Code:
    1. Type conversion already registered from type QPair<QByteArray,QByteArray> to type QtMetaTypePrivate::QPairVariantInterfaceImpl
    To copy to clipboard, switch view to plain text mode 
    I have found the warning is from this Qt’s function:

    Qt Code:
    1. bool QMetaType::registerConverterFunction(QtPrivate::AbstractConverterFunction *f, int from, int to)
    2. {
    3. if (!customTypesConversionRegistry()->insertIfNotContains(from, to, f)) {
    4. qWarning("Type conversion already registered from type %s to type %s",
    5. QMetaType::typeName(from), QMetaType::typeName(to));
    6. if (f)
    7. f->destroy(f);
    8. return false;
    9. }
    10. return true;
    11. }
    To copy to clipboard, switch view to plain text mode 
    I have checked my own code, nobody is calling this function, so it must be inside Qt’s own function. Could any one give me a hint what’s causing this issue or which function actually called the above function inside Qt’s code. I am using Qt 5.3.2. I wonder whether this could be a Qt’s bug instead of mine?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt warning of type conversion already registered

    Does your code ever call qRegisterMetatype() or use Q_DECLARE_METATYPE()?

  3. #3
    Join Date
    Nov 2014
    Posts
    6
    Qt products
    Qt4 Qt5

    Default Re: Qt warning of type conversion already registered

    Quote Originally Posted by ChrisW67 View Post
    Does your code ever call qRegisterMetatype() or use Q_DECLARE_METATYPE()?
    Yes. I did call them. And there are also a bunch of calling inside the generated moc_ file. Could you give more hints?

    Since I dont think I have ever touched the type conversion between QPair<QByteArray,QByteArray> to type QtMetaTypePrivate::QPairVariantInterfaceImpl...
    Last edited by nyaruko; 10th November 2014 at 05:39.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt warning of type conversion already registered

    Those Calls in your code are the most likely triggers for the message you are seeing. If it really bothers you, try to work out which of your calls (not the ui generated code) to the metatype functions triggers the message. It is possible you get that message regardless of what your types are, or that you have types that equate to byte arrays internally.

  5. #5
    Join Date
    Nov 2014
    Posts
    6
    Qt products
    Qt4 Qt5

    Default Re: Qt warning of type conversion already registered

    Quote Originally Posted by ChrisW67 View Post
    Those Calls in your code are the most likely triggers for the message you are seeing. If it really bothers you, try to work out which of your calls (not the ui generated code) to the metatype functions triggers the message. It is possible you get that message regardless of what your types are, or that you have types that equate to byte arrays internally.
    Hi, it seems if I just comment this
    Qt Code:
    1. QNetworkAccessManager network;
    To copy to clipboard, switch view to plain text mode 
    from my code, that warning just won't come out anymore.
    What could be the reason???

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

    Default Re: Qt warning of type conversion already registered

    Where do you have that line in your code? Is it a class member variable, a local variable, a global one?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Aug 2014
    Posts
    16
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt warning of type conversion already registered

    It's in a class member variable. The qRegisterMetaType<QList<QPair<QByteArray,QByteArra y> > >(); call inside the QNetworkAccessManager constructor is failing. Working on getting it to repro in the debugger. It smells like a thread safety issue with qRegisterMetaType, but just guessing at this point.

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

    Default Re: Qt warning of type conversion already registered

    Where do you have threads in your code? How do you use them?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Aug 2014
    Posts
    16
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt warning of type conversion already registered

    think it's just a race condition associated with getting the qWarning message. In this code:

    template <typename T>
    inline bool QtPrivate::IsMetaTypePair<T, true>::registerConverter(int id)
    {
    const int toId = qMetaTypeId<QtMetaTypePrivate::QPairVariantInterfa ceImpl>();
    if (!QMetaType::hasRegisteredConverterFunction(id, toId)) {
    QtMetaTypePrivate::QPairVariantInterfaceConvertFun ctor<T> o;
    static const QtPrivate::ConverterFunctor<T,
    QtMetaTypePrivate::QPairVariantInterfaceImpl,
    QtMetaTypePrivate::QPairVariantInterfaceConvertFun ctor<T> > f(o);
    return QMetaType::registerConverterFunction(&f, id, toId);
    }
    return true;
    }

    If you hit it with two threads at the same time both can get false from QMetaType::hasRegisteredConverterFunction(id, toId). Then the first one that wins registers the converter and the second gets a qWarning about the converter already being registered message. Nothing bad happens unless you are running your code with QT_FATAL_WARNINGS during automated testing which we do. And because of that this comes out as a bug on our side when it really isn't.

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

    Default Re: Qt warning of type conversion already registered

    Quote Originally Posted by don@thegagnes.com View Post
    If you hit it with two threads at the same time
    Do you hit it with two threads at the same time? Where do these threads come in your code?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Aug 2014
    Posts
    16
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt warning of type conversion already registered

    I haven't been able to catch this one in a debugger yet. It is very intermittent. It tends to get hit by automation which is difficult to hook into. I can make it go away by calling qRegisterMetatype on QPair<QByteArray,QByteArray> once right at the start of the app.

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

    Default Re: Qt warning of type conversion already registered

    Look, I am asking a very simple question -- "where do you have threads in your code?". And another one -- "how is the code of these threads related to instantiating QNetworkAccessManager?". Please answer them without mentioning "qRegisterMetaType" or "debugger".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Aug 2014
    Posts
    16
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt warning of type conversion already registered

    QNetworkAccessManager is used on the main thread and also in threads which are used to query map contents from Google and Bing map servers. Both of these threads are started at boot time. Boot time is also when the problem occurs.

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

    Default Re: Qt warning of type conversion already registered

    Do you really need that many instances of QNAM? A secondary question would be if you need threads at all as a single QNAM instance can handle multiple requests simultaneously.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    May 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Qt warning of type conversion already registered

    Quote Originally Posted by wysota View Post
    Do you really need that many instances of QNAM? A secondary question would be if you need threads at all as a single QNAM instance can handle multiple requests simultaneously.
    I have the same issue. It's obviously a race condition during initialisation.
    I address two servers with different IP adresses in different threads with different priorities and different needs (one performs synchronous and the other async backgroud tasks), so using the same QNAM is not an option I guess.
    It's probably no big deal, will try to register the metatype beforehand as don suggested. Just ignoring the warning is not sufficient as it crashes soon. I also wonder in general if not the registerMetaType operation should be protected against such race conditions?

  16. #16
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt warning of type conversion already registered

    qRegisterMetatype() is specifically documented as thread-safe so it should already be serialising competing accesses as required. A small, self-contained example that reproduces the problem would be useful. That will eliminate thread-related curiosities in your code as much as demonstrate them in Qt.

  17. #17
    Join Date
    May 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Qt warning of type conversion already registered

    Quote Originally Posted by ChrisW67 View Post
    qRegisterMetatype() is specifically documented as thread-safe so it should already be serialising competing accesses as required. A small, self-contained example that reproduces the problem would be useful. That will eliminate thread-related curiosities in your code as much as demonstrate them in Qt.
    Qt Code:
    1. qRegisterMetaType<QList<QPair<QByteArray,QByteArray> > >();
    To copy to clipboard, switch view to plain text mode 
    Insert before creating any QNAM and the problem vanishes.
    Providing an example is tricky, as the race condition only happens occasionally. Create and start two or more threads with different priorities (probably lower first, which then gets pre-empted by the second with higher priority), each of which creates a QNAM in its run () method. That should reveal the problem if the timing is "right".

Similar Threads

  1. Type conversion already registered problem
    By Momergil in forum Qt Programming
    Replies: 2
    Last Post: 4th July 2014, 02:10
  2. Type conversion on container templates
    By Alir3z4 in forum Qt Programming
    Replies: 18
    Last Post: 29th January 2012, 23:56
  3. Replies: 3
    Last Post: 16th November 2011, 05:06
  4. PCH and QtCreator warning of not finding the type name
    By kornicameister in forum Qt Programming
    Replies: 3
    Last Post: 2nd November 2010, 18:07
  5. problem in data type conversion
    By sksingh73 in forum Newbie
    Replies: 2
    Last Post: 24th June 2010, 02:12

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.