<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[&quot;QML module not found&quot; error when importing custom qml module]]></title><description><![CDATA[<p dir="auto">Hi</p>
<p dir="auto">In Qt Creator I try to make custom modules working.</p>
<p dir="auto">I created a folder custom_qml with some qml files. The CMakeLists.txt in this folder is this:</p>
<pre><code>set(MODULE_NAME MyButtons)
set(LIB_NAME ${MODULE_NAME}Lib) # MyButtonsLib

qt_add_library(${LIB_NAME} STATIC)

set_target_properties(${LIB_NAME} PROPERTIES AUTOMOC ON)
target_link_libraries(${LIB_NAME} PRIVATE Qt6::Quick)

qt_add_qml_module(${LIB_NAME}
	URI ${MODULE_NAME}
	# VERSION 1.0
	RESOURCE_PREFIX /
	QML_FILES
		RedButton.qml
		GreenButton.qml
)
</code></pre>
<p dir="auto">In my main CMakeLists.txt I added:</p>
<pre><code>add_subdirectory(custom_qml)
target_link_libraries(appstudio
    PRIVATE Qt6::Quick MyButtonsLibplugin
)
</code></pre>
<p dir="auto">The library seems to compile correctly.</p>
<p dir="auto">But now I want to use it.<br />
When in my Main.qml I add the import line:</p>
<pre><code>import MyButtons
</code></pre>
<p dir="auto">The editor shows and error: QML module not found</p>
<p dir="auto">Note that I did add to the main function the line:</p>
<pre><code>engine.addImportPath(":/"); // for importing custom qml modules
</code></pre>
<p dir="auto">Some tutorial told me to do that.</p>
<p dir="auto">So what could be wrong here?</p>
<p dir="auto">I use Qt 6.11.2<br />
I use Qt Creator 20.0.1</p>
]]></description><link>https://forum.qt.io/topic/165044/qml-module-not-found-error-when-importing-custom-qml-module</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 19:55:24 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/165044.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 Aug 2026 22:06:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &quot;QML module not found&quot; error when importing custom qml module on Fri, 28 Aug 2026 13:05:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/simmania">@<bdi>Simmania</bdi></a> said in <a href="/post/839894">"QML module not found" error when importing custom qml module</a>:</p>
<blockquote>
<pre><code>[cmake] CMake Error at custom_qml/MyButtons/CMakeLists.txt:4 (set_target_properties):
[cmake]   set_target_properties Can not find target to add properties to:
[cmake]   MyButtonsLib
</code></pre>
</blockquote>
<p dir="auto">You've swapped the order of <code>qt_add_library()</code> and <code>set_target_properties()</code>. The order in your previous version was fine; you must define the target library first before you can set its properties.</p>
<blockquote>
<p dir="auto">When removing line 4, I get the error message:</p>
<pre><code>[cmake] CMake Error at C:/Qt/6.11.2/msvc2022_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:1539 (message):
[cmake]   Metatype generation requires either the use of AUTOMOC or a manual list of
[cmake]   generated json files
</code></pre>
<p dir="auto">So that lines seems needed.</p>
</blockquote>
<p dir="auto">You don't need it if you called <code>qt_standard_project_setup()</code> at the start of your project. This automatically enables <code>AUTOMOC</code> on all of your targets (and it also enables other features): <a href="https://doc.qt.io/qt-6/qt-standard-project-setup.html#description" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qt-standard-project-setup.html#description</a></p>
<blockquote>
<p dir="auto">Note that I'm not sure about</p>
<pre><code>target_link_libraries(appstudio
	PRIVATE Qt6::Quick MyButtonsLib
)
</code></pre>
<p dir="auto">Maybe that should be</p>
<pre><code>target_link_libraries(appstudio
	PRIVATE Qt6::Quick MyButtonsLibplugin
)
</code></pre>
<p dir="auto">But it seems to make no difference.</p>
</blockquote>
<p dir="auto">For STATIC modules, the official examples use <code>*plugin</code>: <a href="https://github.com/qt/qtdoc/blob/v6.11.2/examples/demos/mediaplayer/CMakeLists.txt#L31-L33" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/qt/qtdoc/blob/v6.11.2/examples/demos/mediaplayer/CMakeLists.txt#L31-L33</a></p>
<p dir="auto">(Note: In practice, you could probably omit "MyButtonsLibplugin" and rely on qmlimportscanner to automatically find it... but I like to specify the link for clarity)</p>
]]></description><link>https://forum.qt.io/post/839899</link><guid isPermaLink="true">https://forum.qt.io/post/839899</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Fri, 28 Aug 2026 13:05:41 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;QML module not found&quot; error when importing custom qml module on Fri, 28 Aug 2026 08:55:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jksh">@<bdi>JKSH</bdi></a></p>
<p dir="auto">Thx a lot.</p>
<p dir="auto">I think I applied all changes you mentioned. But when opening the project in Qt Qcreator now it does not come alive and gives this error:</p>
<pre><code>[cmake] CMake Error at custom_qml/MyButtons/CMakeLists.txt:4 (set_target_properties):
[cmake]   set_target_properties Can not find target to add properties to:
[cmake]   MyButtonsLib
</code></pre>
<p dir="auto">My main CMakeLists.txt looks like this now:</p>
<pre><code>cmake_minimum_required(VERSION 3.16)

project(studio VERSION 0.1 LANGUAGES CXX)

# Fixes the __cplusplus macro mismatch for MSVC
if(MSVC)
    add_compile_options(/Zc:__cplusplus)
endif()

set(CMAKE_CXX_STANDARD_REQUIRED ON)

#set(QT_QML_OUTPUT_DIRECTORY
#    ${CMAKE_BINARY_DIR}/qml
#)

find_package(Qt6 REQUIRED COMPONENTS Quick)

qt_standard_project_setup(REQUIRES 6.11)

add_subdirectory(custom_qml/MyButtons)

# Content of downloaded design from Figma to Qt or similar
if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/importedcontent/CMakeLists.txt")
    add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/importedcontent)
endif()

qt_add_executable(appstudio
    main.cpp
)

qt_add_qml_module(appstudio
    URI studio
    QML_FILES
        Main.qml
        MButton.qml
	DEPENDENCIES
		TARGET MyButtonsLib
)


# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
set_target_properties(appstudio PROPERTIES
#    MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appstudio
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

target_link_libraries(appstudio
	PRIVATE Qt6::Quick MyButtonsLib
)

install(TARGETS appstudio
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
</code></pre>
<p dir="auto">Note that I'm not sure about</p>
<pre><code>target_link_libraries(appstudio
	PRIVATE Qt6::Quick MyButtonsLib
)
</code></pre>
<p dir="auto">Maybe that should be</p>
<pre><code>target_link_libraries(appstudio
	PRIVATE Qt6::Quick MyButtonsLibplugin
)
</code></pre>
<p dir="auto">But it seems to make no difference.</p>
<p dir="auto">My lib CMakeLists.txt looks like:</p>
<pre><code>set(MODULE_NAME MyButtons)
set(LIB_NAME ${MODULE_NAME}Lib) # MyButtonsLib

set_target_properties(${LIB_NAME} PROPERTIES AUTOMOC ON)

qt_add_library(${LIB_NAME} STATIC)

qt_add_qml_module(${LIB_NAME}
	URI ${MODULE_NAME}
	# VERSION 1.0
	QML_FILES
	    RedButton.qml
		GreenButton.qml
)

target_link_libraries(${LIB_NAME} PRIVATE Qt6::Quick)
</code></pre>
<p dir="auto">When removing line 4, I get the error message:</p>
<pre><code>[cmake] CMake Error at C:/Qt/6.11.2/msvc2022_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:1539 (message):
[cmake]   Metatype generation requires either the use of AUTOMOC or a manual list of
[cmake]   generated json files
</code></pre>
<p dir="auto">So that lines seems needed.<br />
Any idea what is wrong now?</p>
]]></description><link>https://forum.qt.io/post/839894</link><guid isPermaLink="true">https://forum.qt.io/post/839894</guid><dc:creator><![CDATA[Simmania]]></dc:creator><pubDate>Fri, 28 Aug 2026 08:55:45 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;QML module not found&quot; error when importing custom qml module on Fri, 28 Aug 2026 04:16:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/simmania">@<bdi>Simmania</bdi></a> said in <a href="/post/839888">"QML module not found" error when importing custom qml module</a>:</p>
<blockquote>
<p dir="auto">The editor shows and error: QML module not found</p>
</blockquote>
<p dir="auto">That message comes from the old code model, which doesn't fully understand custom QML modules.</p>
<p dir="auto">Enable the QML Language Server instead: <a href="https://doc.qt.io/qtcreator/creator-how-to-use-qml-language-server.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qtcreator/creator-how-to-use-qml-language-server.html</a></p>
<p dir="auto">But, you'll also need to make a few more changes (see below).</p>
<blockquote>
<p dir="auto">Note that I did add to the main function the line:</p>
<pre><code>engine.addImportPath(":/"); // for importing custom qml modules
</code></pre>
<p dir="auto">Some tutorial told me to do that.</p>
</blockquote>
<p dir="auto">That tutorial is outdated. This has not been recommended since Qt 6.5 (see <a href="https://www.qt.io/blog/whats-new-for-qml-modules-in-6.5" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.qt.io/blog/whats-new-for-qml-modules-in-6.5</a>) so please remove this.</p>
<p dir="auto">Please share the blog post with the author and ask them author to update their tutorial to reflect current best practices.</p>
<blockquote>
<pre><code>qt_add_qml_module(${LIB_NAME}
	URI ${MODULE_NAME}
	# VERSION 1.0
	RESOURCE_PREFIX /
	QML_FILES
		RedButton.qml
		GreenButton.qml
)
</code></pre>
</blockquote>
<p dir="auto">You've correctly identified that you don't need <code>VERSION</code>. Please also remove <code>RESOURCE_PREFIX /</code> and let it use the default prefix instead, as described in the blog post. Do the same for your main app's QML module.</p>
<p dir="auto">If your code uses something like <code>engine.load("qrc:/Main.qml")</code>, switch it to <code>engine.loadFromModule("studio", "Main")</code> (assuming that your app's QML module uses <code>URI studio</code>)</p>
<blockquote>
<p dir="auto">In my main CMakeLists.txt I added:</p>
<pre><code>add_subdirectory(custom_qml)
target_link_libraries(appstudio
    PRIVATE Qt6::Quick MyButtonsLibplugin
)
</code></pre>
</blockquote>
<p dir="auto">You'll need to set up a few other things. The order below is important:</p>
<pre><code>find_package(Qt6 REQUIRED COMPONENTS Quick)
qt_standard_project_setup(REQUIRES 6.8) # &lt;-- You can use REQUIRES 6.11 if you want

add_subdirectory(custom_qml) # &lt;-- This must be called BEFORE adding your main QML module

# ...

qt_add_qml_module(appstudio
    URI studio
    QML_FILES
        Main.qml
    DEPENDENCIES
        TARGET MyButtonsLib # &lt;-- Now that your custom_qml folder is processed,
                            #     this tells the QML tools where to find your
                            #     custom QML module when processing your app
)
</code></pre>
]]></description><link>https://forum.qt.io/post/839892</link><guid isPermaLink="true">https://forum.qt.io/post/839892</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Fri, 28 Aug 2026 04:16:59 GMT</pubDate></item></channel></rss>