Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. qmetatype.h: error: constexpr variable 'len' must be initialized by a constant expression

qmetatype.h: error: constexpr variable 'len' must be initialized by a constant expression

Scheduled Pinned Locked Moved Unsolved Qt 6
6 Posts 3 Posters 3.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bilsou
    wrote on last edited by bilsou
    #1

    I created a simple application using Qt 6.2.4 and -std=gnu++17. The same code that compiles and runs with Qt 5.15.2 now throws the following error throughout the compilation:

    include/QtCore/qmetatype.h:2167:23: error: constexpr variable 'len' must be initialized by a constant expression
            constexpr int len = QTypeNormalizer{ nullptr }.normalizeTypeFromSignature(begin, end);
                          ^   
    

    The code itself:

    #include <QtWidgets/QApplication>
    #include <QtWidgets/QPushButton>
    
    int main(int argc, char *argv[]) {
      QApplication a(argc, argv);
    
      QPushButton hello("Hello world!", 0);
      hello.resize(500, 60);
    
      hello.show();
      return a.exec();
    }
    

    Any clue what could be going on ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Are you using CMake or qmake ?

      If qmake, try with:

      CONFIG += c++17
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      B 1 Reply Last reply
      0
      • kkoehneK Offline
        kkoehneK Offline
        kkoehne
        Moderators
        wrote on last edited by
        #3

        If what @SGaist suggested didn't help, please also report the full compiler line that results in the error, as well as the compiler version.

        Director R&D, The Qt Company

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          Are you using CMake or qmake ?

          If qmake, try with:

          CONFIG += c++17
          
          B Offline
          B Offline
          bilsou
          wrote on last edited by
          #4

          @SGaist I have tried to reproduce it manually using C++17 with no luck

          clang++ -x c++ -isystem llvm/lib/clang/stable/include -isystem libgcc/include/c++/9.3.0 -isystem libgcc/include/c++/9.3.0/x86_64linux -isystem glibc/include -isystem kernel-headers/include -isystem mesa/include -isystem glu/include -isystem alsa-lib/include -fcoroutines-ts -isystem llvm/lib/clang/stable/include -isystem libgcc/include/c++/9.3.0 -isystem libgcc/include/c++/9.3.0/x86_64linux -isystem glibc/include -isystem kernel-headers/include -isystem mesa/include -isystem glu/include -isystem alsa-lib/include -nostdinc -nostdinc++ -nostdlib -Wall -Werror -Wextra -Wvla -Wimplicit-fallthrough -Winconsistent-missing-destructor-override -Winconsistent-missing-override -Wnon-virtual-dtor -Wpedantic -pedantic -Wshadow -Wthread-safety -Wtype-limits -Wundef -Wunreachable-code -Wno-global-constructors -Wno-missing-field-initializers -Wno-sign-conversion -Wno-sign-compare -Wno-unused-parameter -Wno-format-pedantic -Wno-gnu-statement-expression -Wno-gnu-zero-variadic-macro-arguments -Wno-c11-extensions -Wno-c99-extensions -Wno-gnu-anonymous-struct -Wno-nullability-extension -Wno-nullability-completeness -Wno-language-extension-token -Wno-overlength-strings -Wno-c++17-extensions '-Wno-error=deprecated-declarations' -mavx2 -mbmi2 -mlzcnt -mpclmul -mfma -mf16c -fstack-protector -fPIC '--sysroot=hopefully_inexistent_dirname' -fsized-deallocation -Og -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer '-std=c++17' -B/tools/binutils/bin -fasynchronous-unwind-tables -fPIC -fPIC -I qt/Samples/SampleBundle/SampleBundle#default,private-headers.hmap -I qt/Samples/SampleBundle -I build-out -I qt/Samples/SampleBundle/SampleBundle -isystem qt/QtConcurrent -isystem qt/6.2.4/linux_x64/include -isystem qt/6.2.4/linux_x64/include/QtConcurrent -isystem qt/QtCore -isystem qt/6.2.4/linux_x64/include/QtCore -isystem qt/QtDBus -isystem qt/6.2.4/linux_x64/include/QtDBus -isystem qt/QtGui -isystem qt/6.2.4/linux_x64/include/QtGui -isystem qt/QtNetwork -isystem qt/6.2.4/linux_x64/include/QtNetwork -isystem qt/QtOpenGL -isystem qt/6.2.4/linux_x64/include/QtOpenGL -isystem qt/QtQml -isystem qt/6.2.4/linux_x64/include/QtQml -isystem qt/QtQmlModels -isystem qt/6.2.4/linux_x64/include/QtQmlModels -isystem qt/QtQmlWorkerScript -isystem qt/6.2.4/linux_x64/include/QtQmlWorkerScript -isystem qt/QtQuick -isystem qt/6.2.4/linux_x64/include/QtQuick -isystem qt/QtQuickControls2 -isystem qt/6.2.4/linux_x64/include/QtQuickControls2 -isystem qt/QtQuickShapes -isystem qt/6.2.4/linux_x64/include/QtQuickShapes -isystem qt/QtQuickTemplates2 -isystem qt/6.2.4/linux_x64/include/QtQuickTemplates2 -isystem qt/QtQuickWidgets -isystem qt/6.2.4/linux_x64/include/QtQuickWidgets -isystem qt/QtSvg -isystem qt/6.2.4/linux_x64/include/QtSvg -isystem qt/QtWebSockets -isystem qt/6.2.4/linux_x64/include/QtWebSockets -isystem qt/QtWidgets -isystem qt/6.2.4/linux_x64/include/QtWidgets -isystem qt/QtXcbQpa -Wno-shadow -Wno-deprecated -Wno-inconsistent-missing-destructor-override -Xclang -fdebug-compilation-dir -Xclang . -o qt/Samples/SampleBundle/SampleBundle#compile-moc_SampleApp.cpp.o091a2f2d,default/moc_SampleApp.cpp.o -c -H qt/Samples/SampleBundle/moc_SampleApp.cppSampleBundle/moc_SampleApp.cpp
          

          I saw someone else posting about this issue when trying to upgrade from 5.14 to 6.2. It seems they never managed to get around the issue and stuck to Qt 5.14. I might end up going the same path and stick to Qt 5.15.2 as I have spent too much time on this

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Something is a bit fishy here. You are setting gnu++17 in your project which IIRC is for gcc and you use clang in your test.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • kkoehneK Offline
              kkoehneK Offline
              kkoehne
              Moderators
              wrote on last edited by
              #6

              @bisoftmm , this might be an incompatibility with the many compiler options you set. To debug this further, can you try to strip down the command line to the bare minimum (i.e. leaving out all the -Wxyz , -Wno-xyz options)?

              Is that compiler line by a build system?

              Director R&D, The Qt Company

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved