koldoon
koldoon

Reputation: 191

QQmlApplicationEngine does not accept correct QML when project is built with CMake in CLion

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
}

Upvotes: 2

Views: 1633

Answers (1)

koldoon
koldoon

Reputation: 191

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.

Upvotes: 2

Related Questions