I don't manage to add a file to my QML project with Qt Creator Qt6 - qml

I feel a bit ashamed but I simply don't manage to add a file to my QML project in Qt Creator.
I use Qt 6.2.3 and my build system is qmake.
First off, I created a file MyButton.qml by doing a right click on the folder named QML of a project which only contains a main.qml file.
Then, when I type MyButton in main.qml I can use the autocompletion so I see Qt Creator detects my new type.
But during executation, I got this error :
QQmlApplicationEngine failed to load component
qrc:/MyProject/main.qml:9:5: MyButton is not a type
Anyone knows how to add a file to a project ?
I carefuly followed the official documentation (https://doc.qt.io/qt-6/qtqml-documents-definetypes.html) and several tutorials but nothing works. That's crazy.
EDIT :
I did what JarMan advises but I still get the same error.
Here is an image of my project arborescence
And the content of the qml.qrc file :
<RCC>
<qresource prefix="/">
<file>MyButton.qml</file>
<file>main.qml</file>
</qresource>
</RCC>

I believe the problem you're running into is simply that your executable doesn't know where to find your .qml file because the build folder is usually not the same as the source folder. To fix this, you should create a resource file (you can name it something like qml.qrc) and list all of your QML files in there. This allows the QML file to get bundled into the executable.
An example would look like this:
<RCC>
<qresource prefix="/">
<file>MyButton.qml</file>
</qresource>
</RCC>
Then in your .pro file, add this line:
RESOURCES += qml.qrc
EDIT:
You can do the same thing in Qt Creator.
Step 1:
You might already have a resource file in your project. If so, you'll see it in the Project view on the left side of the window. If you do, you can skip to Step 2. Otherwise, go to File->New File... and select Qt Resource File. Name it qml.qrc (or whatever you like).
Step 2:
Once you've created that file, it should now show up in the Project view on the left. You can right-click on the file name and select Add Existing Files. Choose your MyButton.qml file. That should do exactly what I mentioned in my original answer, but without manually typing any code.

I got the same error with Qt 6.3.1
I found the Qt Creator doesn't generate the qml.qrc file when you select Minimum required Qt version: to Qt 6.2.
So I switched the Minimum required Qt version: to Qt 5.15 in Qt Creator Wizard, the qml.qrc file will generated and my custom component qml file would be included automatically in it.
Also, the .pro configure file has different items between these two Qt version.

Solution 1:
add qml in the pro file:
resources.files = main.qml MyButton.qml
Solution 2:
add a qrc file into project and add qml as resource file

Related

Custom widget in thingworx

Could any body let me know how to create custom widget in thingworx.
I don't have any idea how to create custom widget.
Please help me.
I have to build drag drop custom widget and we can use that custom widget with other widget. e.g with tree widget,... etc.
I would recommend reading the official Extension Package Development Guide:
However, the best way to start making a new widget is to take an existing widget that does something like you want, and modify it. Built in widgets exist at
TomcatRoot\webapps\Thingworx\Common\thingworx\widgets
Here's a very brief guide to getting started with that. If you were to want to copy Textbox:
Open the metadata.xml and change the "TextBox" to "MyWidget".
There are two sections in this file. The "ExtensionPackage" section holds metadata for the pacakge (version, vendor, etc.)
The second section , "Widgets" defines the widget files. Change the name of all these files to use your name e.g. MyWidget.ide.js Don’t forget to change name in the “Widget” xml tag too.
Rename all necessary folder and files, replacing "TextBox" with "MyWidget"
Open the both .js files and change the definition in each to reflect "MyWidget"
In the ide file, change the icon path "widgetIconUrl" and the "name" property.
Select the "ui" folder and the metadata.xml file and package them both into a new zip file. This file should import into Thingworx.
I would suggest searching for or asking this question in the PTC IoT Community, which is much more active for Thingworx developers than StackExchange.
UPDATE: The latest documentation for ThingWorx 9 Extension Package Development Guide can be found here

Add external libraries to my project issue

I try to add external library to my current project, but my project can't pick up the library.
I have MyLib.java file in other directory.
/Users/cat/myfile/github/JavaLib/MyLib.java
I want to my current project (/home/project/HelloWorld/HellowWorld.java) to use my MyLib.java
I'm following the steps to add Library to Intellij(15CE)
Menu->Project Structure->Libraries
click (+) symbol->select Java -> select my path(/home/lib/)
Here is the screenshot
Now that you have added your JavaLib directory to the project you should be able to use the code inside JavaLib in your code now. Intellij should offer auto-complete when you start to type the name of a JavaLib class and automatically include the import for you in your code.
The disabled Apply button you circled isn't an issue. I get that in my view too. It just means nothing has changed that needs to be applied currently.

Import Box2D : file not found

I'm trying to import Box2D library but I have a compilation error : 'Box2D/Box2D.h' file not found.
I tried lots of things to solve this problem but without any success. I'm not using cocos2d so I don't have any templates.
I just drag and drop Box2D folder in my Xcode project (tried to check and uncheck the 'copy to destination folder).
Tried to check 'Always Search User Path' etc ... No success.
If someone has the solution : god bless you !
Just drag and drop the Box2D.h/Bow2D.h to your project.If it is not as simple as that, I can recommend you this tutorial which explain everything you need to know to set up Box 2D in XCode.
EDIT
I have just tried the project in the tut I referenced and i believe you didn't set-up your header search path. Box2D files are intended to be included like this: #include so you need to go to Build Settings then add an entry for the Debug and Release key of the Header Search Paths (under Build Settings)
you are looking as something like this: Debug Box2D_v2.1.2/Box2D

Xcode 4 'QuartzCore/CIColor.h' file not found

I'm running Xcode 4 and trying to follow the steps in Apple's Image Kit Programming Guide (which is written for Xcode 3) on how to work with an Image View and the IKImageView class. I just imported the Quartz and Quartz Core frameworks (from /System/Frameworks directory) to my blank Cocoa Application project using File > Add Files to... menu, but when I try to Run my application I get this error:
Lexical or Preprocessor Issue 'QuartzCore/CIColor.h' file not found
Does anyone know what could be a reason?
Peter Hosey replied:
You're not supposed to import specific headers directly, and especially not from sub-frameworks (such as Core Image, sub-framework of QuartzCore). Only import a framework's overall header, which usually has the same name as the framework.
I didn't import any specific headers directly, I just choose File>Add Files to... then choose /system/Frameworks and choose two folders which contain those frameworks, after that they appeared in my project navigator view as they should, but the code wouldn't compile any more. It shows me NSColor.h file which is found in the AppKit framework, points at this line: #import and says Lexical or Preprocessor Issue 'QuartzCore/CIColor.h' file not found. I have no clue why it wouldn't compile. CI stands for Core Image. I'm now reading a guide on Core Image, maybe this will help. I'd like to post a screenshot but I can't (not enough rights yet).
I just imported the Quartz and Quartz Core frameworks (from /System/Frameworks directory) to my blank Cocoa Application project using File > Add Files to... menu, …
That's not importing; that's just adding it to the project (and hopefully the target). Importing is what you do with the #import directive.
… but when I try to Run my application I get this error: Lexical or Preprocessor Issue 'QuartzCore/CIColor.h' file not found
You're not supposed to import specific headers directly, and especially not from sub-frameworks (such as Core Image, sub-framework of QuartzCore). Only import a framework's overall header, which usually has the same name as the framework.
The problem was that the Guide I used was written for Xcode 3 so when I tried to import/add some frameworks to my project using "File>Add files" menu as described, it did add those frameworks and I could see them in the project navigator, but something went wrong. In Xcode 4 you should use a different way to add/import Frameworks by using the Project Editor> Summary tab> Linked Frameworks and Libraries> Click "+" and then choose the Frameworks you need. That fixed the issue.

import "cocos2d.h" works in some files, but not all

Here is what I did:
In Xcode 4.3.1
File -> New -> Project -> Single view application
Dragged the file cocos2d-ios.xcodeproj into navigator.
In build phases settings : Added : libcocos2d.a (becomes highlighted in red), as a linked library (required).
Added OpenGles.framework, Quartzcore, and libz.dylib
Changed build settings - Set "Always Search User Paths" to YES
Added cocos2d source directory to "User Header Search Paths"
Now, it seems I can type: import "cocos2d.h" , in the app delegate and root view controller that Xcode created. But if I create a new file, and I add the line "import "cocos2d.h"" to the top, Xcode complains that the file is not found. But it seems to build fine. Also, in this new file code sense does not work.
What should I do? Why can I import only in the files that Xcode created? Is there some setting I need to change so that in the files I create, I can import cocos2d ?
EDIT: It seems to build and run fine. I can call methods in the cocos2d api. code sense just doesn't seem to see cocos2d.h in the new files I create.
EDIT - it seems that code sense suggests cocos2d.h when i type : import "
But it does not suggest classes / methods from the cocos2d api.
Turns out I had only added the "user header search paths" to my target, but not in the project settings.
Adding it fixed the problem. I guess the reason it compiled fine was because I had added it to the target, but it didn't work in the text editor since I hadn't added it to the project.
This happened to me as well, even though I did add it to both project and target.
However, what worked for me was to select the RECURSIVE checkbox under "User Header Search Prefixes" (which was set to "/lib/**")
I had same issue.
My project -> Build Settings
Look for the entry for Search Paths
Always Search User Paths - YES
User Header Search paths - "myProjectName/libs" //I put box2d folder here
Hope this help someone.