Results 1 to 8 of 8

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
    400
    Thanked 48 Times in 44 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,743
    Thanks
    214
    Thanked 577 Times in 567 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
    400
    Thanked 48 Times in 44 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,743
    Thanks
    214
    Thanked 577 Times in 567 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
    400
    Thanked 48 Times in 44 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,743
    Thanks
    214
    Thanked 577 Times in 567 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.

Similar Threads

  1. Convert char to QChar?
    By davinciomare in forum Newbie
    Replies: 2
    Last Post: 12th October 2016, 09:38
  2. Convert QString to QChar
    By davinciomare in forum Newbie
    Replies: 1
    Last Post: 12th October 2016, 09:36
  3. integer to QChar
    By saman_artorious in forum Qt Programming
    Replies: 1
    Last Post: 26th February 2013, 17:12
  4. From QString to QChar
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2009, 03:14
  5. size of QChar
    By babu198649 in forum Newbie
    Replies: 5
    Last Post: 4th August 2008, 15: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.