Click here to Skip to main content
11,802,442 members (71,077 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ C QT
So, I'm creating an app in QML, and have created a custom component. To be better organized, I am placing all of my custom components in a "com" subdirectory. I did some research, and found that I needed QML_IMPORT_PATH and a custom qmldir file to create a module so I could import my controls into my project.

My components path is E:/Qt Projects/MyApp/qml/MyApp/com

Inside, I created a qmldir.txt file containing the following:

Button 1.0 Button.qml

Where "Button.qml" is the name of my custom component (in the same directory).

import QtQuick 1.1
Rectangle {
    width: 100
    height: 50

Next I went to "MyApp.Pro" and appended the following:

QML_IMPORT_PATH = E:/Qt Projects

Finally, I went to MyApp.qml and added:

import 1.0

Yet, I am still getting a "module not found" error on that line. When it shows the error during mouseover, it displays a list of the current import paths, and E:/Qt Projects wasn't one of them. I've cleaned, rebuilt my project, ran qmake and everything. Still not working. Is my syntax wrong? Why won't it find my module? I'm a Qt newbie so forgive me if this is a stupid question. Any help is appreciated. Thanks in advance.
Posted 14-Jun-13 14:09pm
Richard MacCutchan at 15-Jun-13 4:54am
Try putting the path in double quotes like: QML_IMPORT_PATH = "E:/Qt Projects". I suspect the space after E:/Qt stops the path search.
RadXPictures at 17-Jun-13 15:43pm
Thanks! It worked... but, after running into a few additional problems, I found that simply adding "import "./com" worked perfectly. Thanks though!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 445
1 KrunalRohit 366
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CPallini 230
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,645
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 14 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100