@GrecKo said in Autocompletion Not Working in QML for C++ Instances:
Don't use setContextProperty to expose your C++ instances.
https://doc.qt.io/qt-6/qtqml-cppintegration-overview.html#choosing-the-correct-integration-method-between-c-and-qml
Okay. Thank you. I've been through those several times and am still rereading and rereading them trying to get a complete understanding of them. I notice they use a pro file to add the components so I'll have to convert that to cmake terms.
I'm new to using Qt6 and the last time I used Qt5 was a few years ago so a lot has changed mainly the use of cmake instead of a pro file which is fine with me and I want to learn to use the cmake build process.
I've been trying to find the "right way" to do this but there seems to be a lot of conflicting posts out there and unfortunately I think many still fall back on the Qt5 processes which may work but don't help someone trying to find the Qt6 way! I use the QObject and QML_ELEMENT and QML_PROPERTY in my classes as well as including the qml registration header. So any help is appreciated.
I have a CMakeLists.txt in my project main which adds a subdirectory for utils in which I have a CMakeLists.txt that creates a static library and adds a qml module which is then linked in the main CMakeList.txt All of this is based on the blog post for Qt6 about the new modules . I assume I still need to include the Q_IMPORT_QML_PLUGIN(utilsPl,ugin) in main.cpp. Is this correct?
Then if I am correct I can use the import utils (the module URI) in my QML modules?
The Qt documentation is much better then most for sure but sometimes I feel since they know the process they use partial examples and leave out what is obvious to them. I'd love a blog on how to create a project from scratch with subdirectories, adding the libraries, and then integrating a sample C++ property and function into QML and include all the steps to do setup in main.cpp and any QML modules and of course a sample going the other way!f
utils/CMakeLists.txt
# CMakeLists.txt to build import backend.
qt_add_library(utils_module STATIC)
qt6_add_qml_module(utils_module
URI utils
VERSION 1.0
SOURCES
utils.h
utils.cpp
)
Main CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(FlightLog VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Set application name for use in building.
set(appName "FlightLogbook")
#find_package(Qt6 COMPONENTS Quick REQUIRED)
# Core is probably redundant due to Quick find
find_package(Qt6 REQUIRED COMPONENTS
Core
Qml
Quick
Sql
)
# Standard project setup
#qt_standard_project_setup()
# The executable
qt_add_executable(FlightLogbook
main.cpp
)
#==============================================================================
# Our subdirectories
add_subdirectory(
importdata
)
add_subdirectory(
fldbase
)
add_subdirectory(
utils
)
#==============================================================================
# QML and other files
qt_add_qml_module(FlightLogbook
URI FlightLog
VERSION 1.0
QML_FILES
main.qml
Initapp.qml
)
set_target_properties(FlightLogbook PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
# Added Core, Qml as private libraries
target_link_libraries(FlightLogbook
PRIVATE Qt6::Core
PRIVATE Qt6::Quick
PRIVATE Qt6::Qml
PRIVATE Qt6::Sql
)
#==============================================================================
# Our libraries
target_link_libraries(
FlightLogbook
PRIVATE import_moduleplugin
PRIVATE fldbase_moduleplugin
PRIVATE utils_moduleplugin
)
# Attempting to put the runtime result in the directory above the build
install(TARGETS FlightLogbook
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ..
)