Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt 6.6.1 Build Error: Cannot invoke "String.length()" because "<parameter1>" is null
Forum Update on Monday, May 27th 2025

Qt 6.6.1 Build Error: Cannot invoke "String.length()" because "<parameter1>" is null

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 3 Posters 3.9k Views
  • 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.
  • 8 Offline
    8 Offline
    8Observer8
    wrote on 27 Dec 2023, 18:30 last edited by
    #1

    Hi,

    I wrote a simple example that just show an OpenGL version. It works on Windows:

    67e8c91a-d483-4c5f-9a7f-3a5ed13e118c-image.png

    But when I try to run it on Android physical device (Redmi 4X) it shows errors:

    078d3d93-8ebb-4ded-a560-403c4dd78999-image.png

    main.cpp

    // #ifdef _WIN32
    // #include <windows.h>
    // extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
    // extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
    // #endif
    
    #include <QtGui/QOpenGLFunctions>
    #include <QtGui/QSurfaceFormat>
    #include <QtOpenGLWidgets/QOpenGLWidget>
    #include <QtWidgets/QApplication>
    #include <QtWidgets/QLabel>
    #include <QtWidgets/QVBoxLayout>
    #include <QtWidgets/QWidget>
    
    class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions
    {
        Q_OBJECT
    
    signals:
        void showInfoSignal(const QString &openGLVersion, const QString &shadingVersion, const QString &vendor);
    
    private:
        void initializeGL() override
        {
            initializeOpenGLFunctions();
            glClearColor(0.f, 1.f, 0.f, 1.f);
            QString version(QString("OpenGL version: %1").arg((const char*) glGetString(GL_VERSION)));
            QString shadingLanguageVersion(QString("GLSL version: %1").arg((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION)));
            QString vendor(QString("Vendor: %1").arg((const char*) glGetString(GL_VENDOR)));
            emit showInfoSignal(version, shadingLanguageVersion, vendor);
        }
    
        void paintGL() override
        {
            glClear(GL_COLOR_BUFFER_BIT);
        }
    };
    
    class MainWindow : public QWidget
    {
        Q_OBJECT
    public:
        MainWindow()
        {
            setWindowTitle("OpenGL Version");
            resize(300, 300);
    
            m_openGLVersionLabel = new QLabel();
            m_shadingLanguageVersionLabel = new QLabel();
            m_vendorLabel = new QLabel();
            OpenGLWidget *openGLWidget = new OpenGLWidget();
    
            m_openGLVersionLabel->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
            m_shadingLanguageVersionLabel->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
            m_vendorLabel->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
    
            QVBoxLayout *layout = new QVBoxLayout();
            layout->addWidget(m_openGLVersionLabel);
            layout->addWidget(m_shadingLanguageVersionLabel);
            layout->addWidget(m_vendorLabel);
            layout->addWidget(openGLWidget);
            setLayout(layout);
    
            connect(openGLWidget, &OpenGLWidget::showInfoSignal, this, &MainWindow::showInfoSlot);
        }
    
    private slots:
        void showInfoSlot(const QString &openGLVersion, const QString &shadingVersion, const QString &vendor)
        {
            m_openGLVersionLabel->setText(openGLVersion);
            m_shadingLanguageVersionLabel->setText(shadingVersion);
            m_vendorLabel->setText(vendor);
        }
    
    private:
        QLabel *m_openGLVersionLabel;
        QLabel *m_shadingLanguageVersionLabel;
        QLabel *m_vendorLabel;
    };
    
    #include "main.moc"
    
    int main(int argc, char *argv[])
    {
        // QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL);
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
        return a.exec();
    }
    

    pro

    QT += core gui openglwidgets widgets
    
    win32: LIBS += -lopengl32
    
    CONFIG += c++17
    
    SOURCES += \
        main.cpp
    
    TARGET = app
    
    1 Reply Last reply
    0
    • 8 Offline
      8 Offline
      8Observer8
      wrote on 27 Dec 2023, 19:08 last edited by 8Observer8
      #4

      I solved the problem! Qt6 doesn't work with jdk-21. I has jdk-17 and installed jdk-21 in additional. Qt Creator automatically changed jdk-17 to jdk-21. I changed it back:

      54533948-ec7e-4955-885f-09aa69f5fb12-image.png

      It works. I use scrcpy to show the physical Android screen to computer:

      3a2cb8a4-b15c-4def-a190-73c46bc2bba7-image.png

      S 1 Reply Last reply 7 Jan 2024, 00:10
      1
      • 8 Offline
        8 Offline
        8Observer8
        wrote on 27 Dec 2023, 18:36 last edited by
        #2

        I tried to add the AA_UseOpenGLES attribute but I have the same errors above

        int main(int argc, char *argv[])
        {
            QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseOpenGLES);
            QApplication a(argc, argv);
            MainWindow w;
            w.show();
            return a.exec();
        }
        
        1 Reply Last reply
        0
        • 8 Offline
          8 Offline
          8Observer8
          wrote on 27 Dec 2023, 18:47 last edited by
          #3

          I wrote another example that shows one QOpenGLWidget without the MainWindow class and without signal/slots. It works on the Desktop but has the same errors when I try to build for Android:

          8450258d-9b61-473d-81f5-7bef17bfde7c-image.png

          main.cpp

          #include <QtGui/QOpenGLFunctions>
          #include <QtGui/QSurfaceFormat>
          #include <QtOpenGLWidgets/QOpenGLWidget>
          #include <QtOpenGL/QOpenGLBuffer>
          #include <QtOpenGL/QOpenGLShaderProgram>
          #include <QtWidgets/QApplication>
          
          class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions
          {
          public:
              OpenGLWidget()
              {
                  resize(350, 350);
              }
          
          private:
              void initializeGL() override
              {
                  initializeOpenGLFunctions();
                  glClearColor(0.4f, 0.8f, 0.9f, 1.f);
          
                  qDebug() << "OpenGL Version:" << (const char*) glGetString(GL_VERSION);
                  qDebug() << "GLSL Version:" << (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION);
                  qDebug() << "OpenGL Vendor:" << (const char*) glGetString(GL_VENDOR);
          
                  QString vertexShaderSource =
                      "attribute vec2 aPosition;\n"
                      "void main()\n"
                      "{\n"
                      "    gl_Position = vec4(aPosition, 0.0, 1.0);\n"
                      "}\n";
          
                  QString fragmentShaderSource =
                      "#ifdef GL_ES\n"
                      "precision mediump float;\n"
                      "#endif\n"
                      "//out vec4 fragColor;\n"
                      "void main()\n"
                      "{\n"
                      "    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
                      "}\n";
          
                  m_program.addShaderFromSourceCode(QOpenGLShader::ShaderTypeBit::Vertex,
                                                    vertexShaderSource);
                  m_program.addShaderFromSourceCode(QOpenGLShader::ShaderTypeBit::Fragment,
                                                    fragmentShaderSource);
                  m_program.link();
                  m_program.bind();
          
                  float vertPositions[] = {
                      -0.5f, -0.5f,
                      0.5f, -0.5f,
                      0.f, 0.5f
                  };
                  m_vertPosBuffer.create();
                  m_vertPosBuffer.bind();
                  m_vertPosBuffer.allocate(vertPositions, sizeof(vertPositions));
                  m_program.setAttributeBuffer("aPosition", GL_FLOAT, 0, 2);
                  m_program.enableAttributeArray("aPosition");
              }
          
              void paintGL() override
              {
                  glClear(GL_COLOR_BUFFER_BIT);
                  glDrawArrays(GL_TRIANGLES, 0, 4);
              }
          
          private:
              QOpenGLShaderProgram m_program;
              QOpenGLBuffer m_vertPosBuffer;
          };
          
          int main(int argc, char *argv[])
          {
              // QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL);
              QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseOpenGLES);
              QApplication app(argc, argv);
              OpenGLWidget w;
              w.show();
              return app.exec();
          }
          

          pro

          QT += core gui openglwidgets widgets
          
          win32: LIBS += -lopengl32
          
          CONFIG += c++17
          
          SOURCES += \
              main.cpp
          
          1 Reply Last reply
          0
          • 8 Offline
            8 Offline
            8Observer8
            wrote on 27 Dec 2023, 19:08 last edited by 8Observer8
            #4

            I solved the problem! Qt6 doesn't work with jdk-21. I has jdk-17 and installed jdk-21 in additional. Qt Creator automatically changed jdk-17 to jdk-21. I changed it back:

            54533948-ec7e-4955-885f-09aa69f5fb12-image.png

            It works. I use scrcpy to show the physical Android screen to computer:

            3a2cb8a4-b15c-4def-a190-73c46bc2bba7-image.png

            S 1 Reply Last reply 7 Jan 2024, 00:10
            1
            • 8 8Observer8 has marked this topic as solved on 27 Dec 2023, 19:08
            • 8 8Observer8
              27 Dec 2023, 19:08

              I solved the problem! Qt6 doesn't work with jdk-21. I has jdk-17 and installed jdk-21 in additional. Qt Creator automatically changed jdk-17 to jdk-21. I changed it back:

              54533948-ec7e-4955-885f-09aa69f5fb12-image.png

              It works. I use scrcpy to show the physical Android screen to computer:

              3a2cb8a4-b15c-4def-a190-73c46bc2bba7-image.png

              S Offline
              S Offline
              swurl
              wrote on 7 Jan 2024, 00:10 last edited by
              #5

              @8Observer8 Having the same issue on JDK 17. What SDK version do you have?

              8 1 Reply Last reply 8 Jan 2024, 22:12
              0
              • S swurl
                7 Jan 2024, 00:10

                @8Observer8 Having the same issue on JDK 17. What SDK version do you have?

                8 Offline
                8 Offline
                8Observer8
                wrote on 8 Jan 2024, 22:12 last edited by 8Observer8 1 Sept 2024, 10:20
                #6

                @swurl where to see the SDK version? I downloaded and installed it by clicking on the link a month ago:

                032c29a3-e4bd-4f11-9ab1-61bb690cadcf-image.png

                When you click on the link above you will redirect to the Command Line Tools with this version:

                fa390e2c-4f6f-4bff-94ae-d2602e5e7cec-image.png

                jsulmJ 1 Reply Last reply 9 Jan 2024, 06:25
                0
                • 8 8Observer8
                  8 Jan 2024, 22:12

                  @swurl where to see the SDK version? I downloaded and installed it by clicking on the link a month ago:

                  032c29a3-e4bd-4f11-9ab1-61bb690cadcf-image.png

                  When you click on the link above you will redirect to the Command Line Tools with this version:

                  fa390e2c-4f6f-4bff-94ae-d2602e5e7cec-image.png

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 9 Jan 2024, 06:25 last edited by
                  #7

                  @8Observer8 said in Qt 6.6.1 Build Error: Cannot invoke "String.length()" because "<parameter1>" is null:

                  where to see the SDK version?

                  Maybe if you click on "SDK Manager"?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • 8 Offline
                    8 Offline
                    8Observer8
                    wrote on 9 Jan 2024, 10:15 last edited by
                    #8

                    2c7c378e-6b83-4489-8eeb-81c9e44d49fd-image.png

                    a5c740c4-c05d-4d08-b906-f80d6b866aa8-image.png

                    1 Reply Last reply
                    0

                    1/8

                    27 Dec 2023, 18:30

                    • Login

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