Qt 6.6.1 Build Error: Cannot invoke "String.length()" because "<parameter1>" is null
-
wrote on 27 Dec 2023, 18:30 last edited by
Hi,
I wrote a simple example that just show an OpenGL version. It works on Windows:
But when I try to run it on Android physical device (Redmi 4X) it shows errors:
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
-
wrote on 27 Dec 2023, 19:08 last edited by 8Observer8
I solved the problem! Qt6 doesn't work with
jdk-21
. I hasjdk-17
and installedjdk-21
in additional. Qt Creator automatically changedjdk-17
tojdk-21
. I changed it back:It works. I use scrcpy to show the physical Android screen to computer:
-
wrote on 27 Dec 2023, 18:36 last edited by
I tried to add the
AA_UseOpenGLES
attribute but I have the same errors aboveint main(int argc, char *argv[]) { QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseOpenGLES); QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); }
-
wrote on 27 Dec 2023, 18:47 last edited by
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:
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
-
wrote on 27 Dec 2023, 19:08 last edited by 8Observer8
I solved the problem! Qt6 doesn't work with
jdk-21
. I hasjdk-17
and installedjdk-21
in additional. Qt Creator automatically changedjdk-17
tojdk-21
. I changed it back:It works. I use scrcpy to show the physical Android screen to computer:
-
-
I solved the problem! Qt6 doesn't work with
jdk-21
. I hasjdk-17
and installedjdk-21
in additional. Qt Creator automatically changedjdk-17
tojdk-21
. I changed it back:It works. I use scrcpy to show the physical Android screen to computer:
wrote on 7 Jan 2024, 00:10 last edited by@8Observer8 Having the same issue on JDK 17. What SDK version do you have?
-
@8Observer8 Having the same issue on JDK 17. What SDK version do you have?
wrote on 8 Jan 2024, 22:12 last edited by 8Observer8 1 Sept 2024, 10:20@swurl where to see the SDK version? I downloaded and installed it by clicking on the link a month ago:
When you click on the link above you will redirect to the Command Line Tools with this version:
-
@swurl where to see the SDK version? I downloaded and installed it by clicking on the link a month ago:
When you click on the link above you will redirect to the Command Line Tools with this version:
@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"?
-
wrote on 9 Jan 2024, 10:15 last edited by
1/8