Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. CMake errors when building Qt simple app.
Forum Updated to NodeBB v4.3 + New Features

CMake errors when building Qt simple app.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 710 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hrant
    wrote on last edited by Hrant
    #1

    I want to use Sublime for developing in Qt. So i decided to pick CMake for this job.
    here is what i've done so far. (and here is the tutorial I tried)

    Folder structure

    .
    ├── build
    ├── CMakeLists.txt
    └── src
        ├── CMakeLists.txt
        ├── main.cpp
        ├── main.qml
        └── main.qrc
    

    main.cpp

    #include <QApplication>
    #include <QQmlApplicationEngine>
    
    int main(int argc, char** argv)
    {
        QApplication app(argc, argv);
        QQmlApplicationEngine engine;
    
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
     
        return app.exec();
    }
    

    main.qml

    import QtQuick 2.0
    import QtQuick.Controls 1.0
    
    ApplicationWindow
    {
        visible: true
        width: 640
        height: 480
        title: qsTr("Minimal Qml")
    }
    

    main.qrc

    <RCC>
        <qresource prefix="/">
            <file>main.qml</file>
        </qresource>
    </RCC>
    

    CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)
    
    find_package(Qt5 COMPONENTS Widgets Qml Quick REQUIRED)
    
    add_subdirectory(src)
    

    src/CMakeLists.txt

    include_directories(${Qt5Widgets_INCLUDE_DIRS} ${QtQml_INCLUDE_DIRS})
    
    add_definitions(${Qt5Widgets_DEFINITIONS} ${QtQml_DEFINITIONS} ${${Qt5Quick_DEFINITIONS}})
    qt5_add_resources(QT_RESOURCES qml.qrc)
    
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    set(CMAKE_AUTOUIC ON)
    set(PROJECT "app")
    
    project(${PROJECT})
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -std=c++11 -fstrict-aliasing -pedantic-errors -pedantic -Wno-deprecated-declarations -Wno-unused-variable")
    
    if(NOT DEFINED HEADERS)
        file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
    endif()
    if(NOT DEFINED SOURCES)
        file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
    endif()
    
    source_group("Header Files" FILES ${HEADERS})
    source_group("Source Files" FILES ${SOURCES})
    
    add_executable(${PROJECT} ${HEADERS} ${SOURCES} ${QT_RESOURCES})
    target_link_libraries(${PROJECT}
        Qt5::Widgets
        Qt5::Qml
        Qt5::Quick
        )
    

    and here is how I use cmake in terminal

    cd build
    cmake ..
    make
    ./app #i would call this command if i have had no errors
    

    after doing make command, terminal shows me following erros>

    errors

    Scanning dependencies of target MinimalQml_autogen
    [ 20%] Automatic MOC and UIC for target MinimalQml
    [ 20%] Built target MinimalQml_autogen
    Scanning dependencies of target MinimalQml
    [ 40%] Building CXX object src/CMakeFiles/MinimalQml.dir/main.cpp.o
    make[2]: *** No rule to make target 'src/qrc_qml.cpp', needed by 'src/CMakeFiles/MinimalQml.dir/qrc_qml.cpp.o'. Stop.
    make[1]: *** [CMakeFiles/Makefile2:92: src/CMakeFiles/MinimalQml.dir/all] Error 2
    make: *** [Makefile:84: all] Error 2

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hrant
      wrote on last edited by
      #2

      Found It! Had to change the folder structure a.k.a. main.qrc to qml.qrc

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved