2
votes

I've got very simple correct Qt QML project written and built with Qt 5.9.1 and qmake that runs well. But I want to use CLion to edit c++ code, so I created CMake project configuration as described in many tutorials in Internet. Building is going fine but when application starts it produces very strange QQmlApplicationEngine errors like if my qml was written totally wrong:

QQmlApplicationEngine failed to load component
main.qml:1 Expected token `numeric literal'
main.qml:1 Expected a qualified name id

Here is my configuration under MacOS X: (Note: I do not use QRC on purpose!)

CMakeLists.txt:

cmake_minimum_required(VERSION 3.8)
project(simple_project)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(Qt5 5.9.1 REQUIRED Core Widgets Gui Qml Quick)

set(SOURCE_FILES
        main.cpp
        main.qml)

add_executable(simple_project ${SOURCE_FILES})
target_link_libraries(simple_project
        Qt5::Core
        Qt5::Widgets
        Qt5::Gui
        Qt5::Qml
        Qt5::Quick)

main.cpp:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[]) {
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load("main.qml");

    return app.exec();
}

main.qml lies in the same directory where executable is:

import QtQuick.Controls 2.1
import QtQuick 2.7
import QtQuick.Layouts 1.2

ApplicationWindow {
    visible: true
    width: 480
    height: 320
}
1
Have you added your .qml to a .qrc?eyllanesc
@eyllanesc I don't use qrc, i'm just loading local *.qml file in the same directory. As you can see, qml engine finds file well, but it can't parse it somehow.koldoon
Should main.qml be in the same folder as your executable?eyllanesc
No, this is just an example of a simple project with as a few dependencies as possible.koldoon
Please provide an mvce, this implies that you reproduce your error, which is consistent. I just tried it works for me.eyllanesc

1 Answers

2
votes

After many tries using different editors I found an issue in CLion 2017.2 when it adds some unprintable symbol in the first position of files. Problem solves if open file in (for example) mcedit and remove the first "space" symbol from the qml file.