Skip to content
  • 0 Votes
    2 Posts
    1k Views
    T

    I've developed a hackish workaround - if you're frustrated by this issue too, this "fix" is ugly but might help in the short-term:

    I noticed that Qt Creator still recognizes the old qmlRegisterType function calls if they're invoked from main in a project. So naturally, I made a custom compiler step for qmake that generates a header file with all QML_ELEMENT-tagged classes registered in a function.

    First, make sure you've set up qmltypes in your project as usual - your QML_IMPORT_NAME and all that is set.

    Add to the bottom of MyProject.pro:

    type_registrar_unfucker.name = type_registrar_unfucker type_registrar_unfucker.input = TYPE_REGISTRAR_SOURCES type_registrar_unfucker.commands = python3 $$PWD/type_unfuck.py ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} $$QML_IMPORT_NAME $$QML_IMPORT_MAJOR_VERSION type_registrar_unfucker.output = ${QMAKE_FILE_IN_BASE}.h type_registrar_unfucker.clean = ${QMAKE_FILE_IN_BASE}.h type_registrar_unfucker.variable_out = HEADERS QMAKE_EXTRA_COMPILERS += type_registrar_unfucker TYPE_REGISTRAR_SOURCES += $$OUT_PWD/myproject_metatypes.json

    Add as type_unfuck.py in your source directory:

    # type unfuck # ----------- # This python script deals with the issue of Qt Creator not being able to recognize element types # registered using 'QML_ELEMENT'. # # It does so by generating a header, 'myprojectname_metatypes.h'. # Include this header ONLY in main.cpp, and then call `registerTypes()` first thing in `main`. # Then, Qt Creator will stop whining. import sys import json source_path = sys.argv[1] dest_path = sys.argv[2] import_name = sys.argv[3] import_major = sys.argv[4] with open(source_path) as f: data = json.load(f) includes = ["QtQml"] types = [] for file in data: includes.append(file["inputFile"]) for type in file["classes"]: if "classInfos" in type and {"name":"QML.Element","value":"auto"} in type["classInfos"]: types.append(type["className"]) with open(dest_path, 'w') as f: for i in includes: f.write(f'#include <{i}>\n') f.write('void registerTypes() {\n') for t in types: f.write(f'\tqmlRegisterType<{t}>("{import_name}", {import_major}, 0, "{t}");\n') f.write('}\n')

    Then, just add #include <myproject_metatypes.h> to your project's main.cpp and invoke registerTypes(); immediately in your main function. Build your project, then click on Tools -> QML/JS -> Reset Code Model, and Qt Creator should now recognize your custom components correctly.

  • 1 Votes
    1 Posts
    495 Views
    No one has replied
  • 0 Votes
    2 Posts
    492 Views
    KroMignonK

    I found a solution for my problem.
    I had to set renderType=Text.QtRendering to solve the issue.
    With Qt 5.4.2, I had to set renderType=Text.NativeRendering

    Very strange to me, but works ;)

    Regards

    Fabrice

  • 0 Votes
    5 Posts
    5k Views
    P

    Release builds using the QtQuick compiler generate a qtquickcompiler_loader.cpp file and *_qml.cpp files where * matches the name of your individual *.qml files all within a ".qtquickcompiler" folder within the "build-*-Release" output folder. I verified this with a commercial license Qt 5.9.

    Debugging QML is not compatible with the QtQuick compiler; using default settings to build a Debug executable will not use the QtQuick compiler.