Details
-
Bug
-
Resolution: Cannot Reproduce
-
Not Evaluated
-
None
-
Qt Creator 4.12.4
-
None
Description
I just wanted to learn how to add an additional Qml file to a qmlproject.
Right clicked on project name and selected "add new"
selected "General" and "Empty file". I gave it the name
"Str.qml". Since it was empty, i copied the two imports from the
original qml file.
i created what I thought was a simple Item.
Str.qml.
=====================================
import QtQuick 2.12
import QtQuick.Window 2.12
Item
{ property String text: "" }=======================================
I added a call to Str in the main qml file
Item1.qml
=========================================
import QtQuick 2.12
import QtQuick.Window 2.12
import "Str.qml"
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle {
Str
{ text: "this is a string" } }
}
=================================================
When I tried to run it I received the following error messages
===============================================================
21:03:23: Starting /home/leemke/Qt/5.15.0/gcc_64/bin/qmlscene /home/leemke/proj/qt/Item1/Item1.qml...
file:///home/leemke/proj/qt/Item1/Item1.qml:13 Type Str unavailable
file:///home/leemke/proj/qt/Item1/Str.qml:7 String is not a type
==============================================================
21:03:23: /home/leemke/Qt/5.15.0/gcc_64/bin/qmlscene exited with code 255
So I added an import: ' import "Str.qml" ' to the main file. This resulted in:
==============================================================
21:05:10: Starting /home/leemke/Qt/5.15.0/gcc_64/bin/qmlscene /home/leemke/proj/qt/Item1/Item1.qml...
file:///home/leemke/proj/qt/Item1/Item1.qml:3 "Str.qml": no such directory
21:05:10: /home/leemke/Qt/5.15.0/gcc_64/bin/qmlscene exited with code 255
==================================================================
What am I doing wrong?
I did the same project but used the normal QT Quick project.
And received an error message that "String" (with capital S is not a valid type.
Sorry but older Java habits are hard to break. The compiled version worked
correctly after this one change.
It would have been nice if the qmlscene would have given a better error
message.
I am wrong: changing the property to type "string". It did not fix the problem.
It still noted that the "import" file for "Str.qml" could not be found.
----------------------------------------------------------
Immediately after fresh install, here is what I experienced:
1. created the new project (qmlproject) and added another file.
(item1.qml and Str.qml) both files have essentially the same code
(the Rectangle object in item1.qml is not present).
2. The behavior was the same. With and without the "import Str.qml" file.
3. I changed the Str element in item1.qml to mirror what is in the Str.qml file.
including the "property definition".
4. I ran the modified item1.qml. It worked.
5. I then changed the code back to invoking 'Str
and ran it. This time it worked (without the import statement).
6. I ran it with the import statement, but it still objected that it
could not find "Str.qml".
7. It continues to work without the import statement.
I have no idea why this "changed" the environment. I don't know
if it fixed it or merely appears to have implemented the change.
That is up to you to figure out.