Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-101660

Q_OBJECT causes a parse error in android applications

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P1: Critical
    • None
    • 6.2.2, 6.3.0 Alpha, 6.3.0 Beta2
    • Build System
    • None
    • OS: Windows 10 x64
      Compiler: Android Clang (ndk 21.3.6528147)
    • Android

    Description

      If a class contains Q_OBJECT macro project isn't compiled for Android.

      :\Qt\6.2.2\android_x86\include\QtCore\qnamespace.:56:1: error: error: Parse error at "__attribute__"

      Test.h

      #pragma once
      
      #include <QObject>
      
      class Test : public QObject
      {
          Q_OBJECT
      public:
          Test();
      };
      
      

      Test.cpp

      #include "Test.h"
      
      Test::Test()
      {
      }
      

      main.cpp

      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          const QUrl url(QStringLiteral("qrc:/main.qml"));
          QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                           &app, [url](QObject *obj, const QUrl &objUrl) {
              if (!obj && url == objUrl)
                  QCoreApplication::exit(-1);
          }, Qt::QueuedConnection);
          engine.load(url);
      
          return app.exec();
      }
      

      android_test_qt6.pro

      QT += quick
      
      CONFIG += c++11
      
      SOURCES += \
              main.cpp \
              src/Test.cpp
      
      RESOURCES += qml.qrc
      
      # Additional import path used to resolve QML modules in Qt Creator's code model
      QML_IMPORT_PATH =
      
      # Additional import path used to resolve QML modules just for Qt Quick Designer
      QML_DESIGNER_IMPORT_PATH =
      
      # Default rules for deployment.
      qnx: target.path = /tmp/$${TARGET}/bin
      else: unix:!android: target.path = /opt/$${TARGET}/bin
      !isEmpty(target.path): INSTALLS += target
      
      INCLUDEPATH += $$PWD/include
      
      HEADERS += \
          include/Test.h
      
      

      main.qml

      import QtQuick
      
      Window {
          id: root
      
          width: 640
          height: 480
      
          visible: true
      }
      

      I also compiled with Mingw64 for Windows, with gcc for Linux and it works fine. I cleaned up and reran qmake but nothing changed. Commenting Q_OBJECT it compiles fine, but I need signals and slots. How can I fix this? Thank you in advance.

       

      Compile output:

      19:04:51: Running steps for project android_test_qt6...
      19:04:51: Starting: "E:\Qt\6.2.2\android_x86\bin\qmake.bat" E:\Progs\Qt\android_test_qt6\android_test_qt6.pro -spec android-clang "CONFIG+=debug" "CONFIG+=qml_debug"
      19:04:53: The process "E:\Qt\6.2.2\android_x86\bin\qmake.bat" exited normally.
      19:04:53: Starting: "E:\Android\Sdk\ndk\21.3.6528147\prebuilt\windows-x86_64\bin\make.exe" -f E:/Progs/Qt/build-android_test_qt6-Android_Qt_6_2_2_Clang_x86-Debug/Makefile qmake_all
      make: Nothing to be done for 'qmake_all'.
      19:04:53: The process "E:\Android\Sdk\ndk\21.3.6528147\prebuilt\windows-x86_64\bin\make.exe" exited normally.
      19:04:53: Starting: "E:\Android\Sdk\ndk\21.3.6528147\prebuilt\windows-x86_64\bin\make.exe" -j4
      E:\Qt\6.2.2\mingw_64\bin\moc.exe -DQT_QML_DEBUG -DQT_QUICK_LIB -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_QMLMODELS_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB --include E:/Progs/Qt/build-android_test_qt6-Android_Qt_6_2_2_Clang_x86-Debug/moc_predefs.h -IE:/Qt/6.2.2/android_x86/mkspecs/android-clang -IE:/Progs/Qt/android_test_qt6 -IE:/Progs/Qt/android_test_qt6/include -IE:/Qt/6.2.2/android_x86/include -IE:/Qt/6.2.2/android_x86/include/QtQuick -IE:/Qt/6.2.2/android_x86/include/QtOpenGL -IE:/Qt/6.2.2/android_x86/include/QtGui -IE:/Qt/6.2.2/android_x86/include/QtQmlModels -IE:/Qt/6.2.2/android_x86/include/QtQml -IE:/Qt/6.2.2/android_x86/include/QtNetwork -IE:/Qt/6.2.2/android_x86/include/QtCore -I. -IE:/MinGW/lib/gcc/mingw32/9.2.0/include/c++ -IE:/MinGW/lib/gcc/mingw32/9.2.0/include/c++/mingw32 -IE:/MinGW/lib/gcc/mingw32/9.2.0/include/c++/backward -IE:/Android/Sdk/ndk/21.3.6528147/toolchains/llvm/prebuilt/windows-x86_64/lib64/clang/9.0.8/include -IE:/MinGW/include ..\android_test_qt6\include\Test.h -o moc_Test.cpp
      :/Qt/6.2.2/android_x86/include/QtCore/qnamespace.:56:1: error: Parse error at "__attribute__"
      make: *** [Makefile:705: moc_Test.cpp] Error 1
      19:05:00: The process "E:\Android\Sdk\ndk\21.3.6528147\prebuilt\windows-x86_64\bin\make.exe" exited with code 2.
      Error while building/deploying project android_test_qt6 (kit: Android Qt 6.2.2 Clang x86)
      When executing step "Make"
      19:05:00: Elapsed time: 00:09.
      

      gradle.properties

      android.bundle.enableUncompressedNativeLibs=false
      androidBuildToolsVersion=32.1.0-rc1
      androidCompileSdkVersion=30
      androidNdkVersion=21.3.6528147
      buildDir=build
      qt5AndroidDir=E:/Qt/6.2.2/android_x86/src/android/java
      qtAndroidDir=E:/Qt/6.2.2/android_x86/src/android/java
      qtMinSdkVersion=23
      qtTargetAbiList=x86
      qtTargetSdkVersion=30
      

      Gradle:7.0.2

       

      P.S: on Linux Ubuntu 20.04.4 x64 anything works good.

      Attachments

        1. image-2022-03-12-19-19-45-507.png
          image-2022-03-12-19-19-45-507.png
          18 kB
        2. screenshot-2.png
          screenshot-2.png
          85 kB
        3. screenshot-3.png
          screenshot-3.png
          89 kB
        4. screenshot-4.png
          screenshot-4.png
          84 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtbuildsystem Qt Build System Team
            dime_e Ivan Samti4
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes