Results 1 to 12 of 12

Thread: 'QChar::QChar(ushort) noexcept': member function already defined or declared

  1. #1
    Join Date
    Jul 2018
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default 'QChar::QChar(ushort) noexcept': member function already defined or declared

    I am using visual studio 2017 and getting this error when building my project with Qt 5.11.1. Any idea how to solve this?

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    405
    Thanked 51 Times in 47 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 'QChar::QChar(ushort) noexcept': member function already defined or declared

    Looks like you're compiling your project with compiler switch /Zc:wchar_t- which treats wchar_t as simple ushort

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

    mbardet (6th August 2018)

  4. #3
    Join Date
    Jul 2018
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: 'QChar::QChar(ushort) noexcept': member function already defined or declared

    Thanks.
    But when my project needs it otherwise it won't build. It used to work with qt 5.8. Is there a workaround in Qt without having to change my project?

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,812
    Thanks
    216
    Thanked 590 Times in 580 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: 'QChar::QChar(ushort) noexcept': member function already defined or declared

    Qt has been using the /Zc:wchar_t flag since 5.0 was released, and the binaries downloaded from the Qt web site have all been built that way. If you have been building your own Qt binaries, then you've been building them with the wrong flag setting.
    <=== 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.

  6. #5
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    405
    Thanked 51 Times in 47 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 'QChar::QChar(ushort) noexcept': member function already defined or declared

    It should work by modifying the qstring header file - simply remove the problematic ctor.

  7. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,812
    Thanks
    216
    Thanked 590 Times in 580 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: 'QChar::QChar(ushort) noexcept': member function already defined or declared

    It should work by modifying the qstring header file - simply remove the problematic ctor.
    That's not a solution, that's a kludge. Changing the definition of a class means you now have a mismatch between Qt (which was built using the unmodified header) and application code (which was built with a different definition for QChar).

    The /Zc:wchar_t vs. /Zc:wchar_t- issue is a fundamental difference and will affect every piece of code compiled and linked into the project, and will likely cause run-time errors as well. The correct approach would be to discover the source of the problem (which isn't in the Qt source code) and fix it there. Trust me, I've been there. You cannot mix and match the two language options. CHoose one or the other, and build -everything- to that choice.
    <=== 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.

  8. #7
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    405
    Thanked 51 Times in 47 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 'QChar::QChar(ushort) noexcept': member function already defined or declared

    I'm sorry but that's not true. The wchar_t switch does not change the ABI in any way. It just says if wchar_t should be treated as ushort or not. Therefore it is save to link against a library compiled against another /Zc:wchar_t switch as long as you don't pass a wchar_t between the lib/executable.
    But in the long term one should not mix those two.

  9. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,812
    Thanks
    216
    Thanked 590 Times in 580 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: 'QChar::QChar(ushort) noexcept': member function already defined or declared

    as you don't pass a wchar_t between the lib/executable.
    Which for any practical purpose is nearly impossible to avoid.

    This kind of kludge might be fine for home-grown, single user projects, but it is unacceptable for commercial code. By kludging instead of actually solving the problem, it creates a maintenance and reliability issue. Someone will have to remember to "fix" that header file on every machine where the code is built, and remember to "fix" it again with every new release of Qt. Someone will also have to remember to tell every developer who works on the project, to make sure they don't accidentally try to pass a wchar_t variable into Qt or vice-versa, or use any third-party library that does the same. Years from now when the original developers have moved on but there are still bugs to fix, someone has to remember or be forced to waste time discovering why the new code has led to a compilation or regression test failure.
    <=== 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.

  10. #9
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    405
    Thanked 51 Times in 47 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 'QChar::QChar(ushort) noexcept': member function already defined or declared

    The (more or less) exact change I proposed is now in official Qt: https://codereview.qt-project.org/#/c/235144/
    No need to hack the header file with Qt5.11.2 / Qt 5.12 anymore ...

  11. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,812
    Thanks
    216
    Thanked 590 Times in 580 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: 'QChar::QChar(ushort) noexcept': member function already defined or declared

    Not exactly. The change you suggested only comes into play when someone -uses- the header containing the QChar constructor. In that case library still contains code with an inconsistent definition of wchar_t. The change to the Qt sources affects not only the use of the header but the library build itself so that everything is now internally and externally consistent.

    In any case, if the size and layout of wchar_t and ushort are the same regardless of the compiler flag, it probably doesn't make any difference in fact. I do know that if you try to mix stdlib code (particularly std:: wstring) with QString code where Qt was compiled with a different version of the flag from the code that uses wstring, you get link-time errors because the mangled names of the functions do not match.
    <=== 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.

  12. #11
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    405
    Thanked 51 Times in 47 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: 'QChar::QChar(ushort) noexcept': member function already defined or declared

    It's an inline ctor, you won't find any code inside the Qt library for it...
    /edit: therefore it will even work when you compile Qt with /Zc:wchar_t- and your lib with /Zc:wchar_t+ or the other way round.

  13. #12
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,812
    Thanks
    216
    Thanked 590 Times in 580 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: 'QChar::QChar(ushort) noexcept': member function already defined or declared

    OK, I guess because this is a non-virtual method, it is resolved statically at compile-time and thus has no effect on either the class layout or the vtable. If the library is compiled with the code in place, it will generate a reference to a method that is never called externally by a caller using code compiled with the constructor commented out.

    It is still hard for me to believe you can mix and match code from Qt, an app, and third-party libraries using different values for the flag and not end up getting into trouble somewhere.
    <=== 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.

Similar Threads

  1. Convert char to QChar?
    By davinciomare in forum Newbie
    Replies: 2
    Last Post: 12th October 2016, 10:38
  2. Convert QString to QChar
    By davinciomare in forum Newbie
    Replies: 1
    Last Post: 12th October 2016, 10:36
  3. integer to QChar
    By saman_artorious in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2013, 18:12
  4. From QString to QChar
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2009, 04:14
  5. size of QChar
    By babu198649 in forum Newbie
    Replies: 5
    Last Post: 4th August 2008, 16:36

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.