PDA

View Full Version : qrc:/main.qml:48:35: Unable to assign QQuickRectangle to QQuickAnchorLine



sylas
14th December 2016, 10:41
Hi all ! Last year I built with success a quickcalculator. I used then the Linux O.S. 14. Now with my O.S 16 build fails at the moment I make it "run". I have the message I give on my title: qrc:/main.qml:48:35: Unable to assign QQuickRectangle to QQuickAnchorLine. I suppose that my new Qt Creator has some install missing. Have you an idea of what plugin is missing ?? Many thanks

anda_skoa
14th December 2016, 11:40
Sounds like a problem in the code.

Something like


anchors.left: parent

instead of


anchors.left: parent.left

i.e. passing a reference to an object to an anchor line instead of passing the anchor line of that object.

Cheers,
_

sylas
14th December 2016, 12:40
Here is the code. Look please at the commented line. Thanks for your help.

//main.qml
import QtQuick 2.3//2.3 sur livre

Rectangle {
width: 360
height: 200
color: "grey"

TextInput {
id: argument1
anchors.left: parent.left
width: 160
anchors.top: parent.top
anchors.topMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
text: "2"
font.pointSize: 18
}

TextInput {
id: argument2
anchors.right: parent.right
width: 160
anchors.top: parent.top
anchors.topMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
text: "2"
font.pointSize: 18
}

Text {
id: result
anchors.left: parent.left
anchors.right: parent.right
anchors.top: argument2.bottom
anchors.topMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
text: "4"
font.pointSize: 24
}

Row {
id: buttonRow
width: 317
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.hotizontalCenter//I added ".horizontalCenter". Now "debugging is enabled"
anchors.bottomMargin: 20
spacing: 20
Button {
id: plusButton
operation: "+"
onClicked: result.text = parseFloat(argument1.text) + parseFloat(argument2.text)
}

Button {
id: minusButton
operation: "-"
onClicked: result.text = parseFloat(argument1.text) - parseFloat(argument2.text)
}

Button {
id: timesButton
operation: "*"
onClicked: result.text = parseFloat(argument1.text) * parseFloat(argument2.text)
}

Button {
id: divideButton
operation: "/"
onClicked: result.text = parseFloat(argument1.text) / parseFloat(argument2.text)
}
}
}

anda_skoa
15th December 2016, 11:36
anchors.horizontalCenter defnitely needs one of the three vertical anchor lines as its value, i.e. "parent.left", "parent.right" or "parent.horizontalCenter"

Just parent, which you had previously if I understood you correctly, would not work.

Btw, your code snippet above has a typo in the second "horizontalCenter"

Cheers,
_

sylas
15th December 2016, 14:20
I tried the 3 cases. Now a paste of what happens with parent.horizontalCenter: QML debugging is enabled. Only use this in a safe environment.---- The problem appears onlly when I "run". No problem when it is building. It is strange this project worked well last year with my O.S Linux 14.O4. Now with my O.S. 16.04 it doesn't work.

anda_skoa
15th December 2016, 17:29
If you had "parent" as the value for the horizontalCenter then it just didn't report a warning, it definitely did not work.
Not having that anchor set might be ok, but then you could just remove it.

Cheers,
_

sylas
15th December 2016, 18:04
I removed all the line with // Now "application output" says:
Starting /home/sylvain/build-quickcalc-Qt_5_5_1_in_PATH_qt5_invalid-Debug/quickcalc...
QML debugging is enabled. Only use this in a safe environment.
Nothing wrong while building. The above message appears only when I "run". This project comes from "Application Development with Qt Creator- 2nd edition" of the book of Ray Rischpater.

anda_skoa
16th December 2016, 09:52
So everthing is working now?

Cheers,
_

sylas
16th December 2016, 15:28
Unfortunately it does not work. In the book he speeks only of two files, Button.qml and main.qml. No trace of a main.cpp. I already gave to you " main.qml " . I give you now "Button.qml". Maybe you can advance with it.

//Butoon.qml
import QtQuick 2.0
Rectangle {
id: button
width: 64
height: 64
property alias operation: buttonText.text
signal clicked
color: "green"
Rectangle {
id: shade
anchors.fill: button;
color: "black"; opacity: 0
}
Text {
id: buttonText
anchors.centerIn: parent;
color: "white"
font.pointSize: 16
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
button.clicked();
}
}
states: State {
name: "pressed"; when: mouseArea.pressed == true
PropertyChanges { target: shade; opacity: .4 }
}
}

sylas
17th December 2016, 09:11
In the bundle of codes of this project I found many files. I added one viewer.cpp and a viewer.h. In the designer mode I see the calculator very well. It seems ready for use. Now nothing about my first problem of anchor. The only problem I have now is (in Application Output): "make sure to deploy Qt with accessibility plugins". Very well but where I can find these plugins ?? Have you an idea ?? Cheers

anda_skoa
17th December 2016, 10:43
Unfortunately it does not work.

You have given no indication what problem you are having.



In the book he speeks only of two files, Button.qml and main.qml. No trace of a main.cpp.

You don't necessarily need any C++ files.
E.g. you could simply launch main.qml using "qmlscene" or as a "QtQuick UI" project in QtCreator.


Now nothing about my first problem of anchor.

Great.



The only problem I have now is (in Application Output): "make sure to deploy Qt with accessibility plugins".

That's not a problem unless you need accessibility support.
Do you?

Cheers,
_

sylas
17th December 2016, 11:35
I looked everywhere for Qt plugins, even with my terminal. Now nothing about plugins in "Application Output". I can see very well the calculator in the "Design" mode. But "show" impossible. Maybe there is an error in the main.cpp. Here is its code:

//main.cpp
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"

int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);

QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/QtQuickCalculator/main.qml"));
viewer.showExpanded();//origin
// viewer.show();


}

anda_skoa
17th December 2016, 15:51
I looked everywhere for Qt plugins, even with my terminal.

As I said, if you don't need accessiblity, don't bother looking for plugins that you don't need.



But "show" impossible.

Why didn't you say so before?

So when you run the program you don't see a window or does the window not have any content?

Have you tried running the main.qml with "qmlscene"?

Cheers,
_

sylas
17th December 2016, 18:23
1. I don't understand "running the main.qml with "qmlscene"".
2. The last message of "Application Output" is:
file:///home/sylvain/build-quickcalc-Qt_5_5_1_in_PATH_qt5_invalid-Debug/qml/QtQuickCalculator/main.qml: File not found
/home/sylvain/build-quickcalc-Qt_5_5_1_in_PATH_qt5_invalid-Debug/quickcalc exited with code 0
3. I must say to you that the name I gave to the project is "quickcalc", because I noticed with other projects that the name of the project is not compulsory.
Many thanks for your help.

anda_skoa
18th December 2016, 12:05
1. I don't understand "running the main.qml with "qmlscene"".

qmlscene mai.qml

in a shell that has qmlscene in $PATH



2. The last message of "Application Output" is:
file:///home/sylvain/build-quickcalc-Qt_5_5_1_in_PATH_qt5_invalid-Debug/qml/QtQuickCalculator/main.qml: File not found

See, an actual error message is way more informative than posting random bits of information.
Looks like the file you are trying to load does not exist or you have specified a wrong path.



3. I must say to you that the name I gave to the project is "quickcalc", because I noticed with other projects that the name of the project is not compulsory.

Yes, the name of the project doesn't really matter.

Cheers,
_

sylas
19th December 2016, 07:25
qmlscene: marvellous ! Calculator works very well. But is it possible you try yourself this demoniac quick application ? Only Button.qml and main.qml are necessary, and you have them above.1. you create the project with Qt Creator: "Application" and "QtQuickApplication"
2. main.cpp already appears. I don't touch it. (it is not the main.cpp I sent to you above). Now you add the file "Button.qml". You can look already in the Design mode the button.
3. You add "main.qml". You can look already in the design mode the calculator.
4. You build the project. No error message..
5. you run it. Then you see the "Application Output" message I gave at the beginning of this thread.
I think that if you don't have the message and your project works well the error is in my Linux or in a pluggin missing. Thank you very much. Cheers

anda_skoa
19th December 2016, 10:20
This has nothing to do with plugins, the error clearly indicates that the file does not exist where the program looks for it.

Most likely cause: the two QML files are in your project directory and you have a shadow build (out of source build).
So the working directory of the application is not the source directory.

Several options:
1) Start the application with the source directory as the working directory
2) Copy or link the QML files into the build directory
3) Put the QML files into a Qt resource and load them from there

Cheers,
_

sylas
19th December 2016, 12:48
I use another project more complete. First paste of the "Application Output":
Starting /home/sylvain/build-quickcalc-Qt_5_5_1_in_PATH_qt5_invalid-Debug/quickcalc...
QML debugging is enabled. Only use this in a safe environment.
file:///home/sylvain/build-quickcalc-Qt_5_5_1_in_PATH_qt5_invalid-Debug/qml/QtQuickCalculator/main.qml: File not found
/home/sylvain/build-quickcalc-Qt_5_5_1_in_PATH_qt5_invalid-Debug/quickcalc exited with code 0
The files; quickcalc.pro, deployment.pri, qtquick2applicationviwer.h, main.cpp, qtquick2applicationviewer.cpp Ressources: Button.qml, main.qml Others: qmldir
It is very hard for me. Have you an idea ? Thanks and cheers

anda_skoa
19th December 2016, 13:48
file:///home/sylvain/build-quickcalc-Qt_5_5_1_in_PATH_qt5_invalid-Debug/qml/QtQuickCalculator/main.qml: File not found

Your program, the last one and this one, tells you that there is no

/home/sylvain/build-quickcalc-Qt_5_5_1_in_PATH_qt5_invalid-Debug/qml/QtQuickCalculator/main.qml

file.



It is very hard for me. Have you an idea ? Thanks and cheers

Files in a file system are address with by name, which consists of the the actual file name and path.
A path can be absolute or relative.
Absolute means it has all information there is, a full sequence of directory names from the top level of the directory tree to the file itself.

A relative path is just a filename or the filename plus some directories. The runtime environment will then prepend the program's working directory to create a full/absolute path for the actual access operation.

See https://en.wikipedia.org/wiki/Path_(computing)

Cheers,
_

sylas
19th December 2016, 13:53
12252
You can see better with the image

anda_skoa
19th December 2016, 19:40
So you added the files to the resource, but forgot to change the path when loading main.qml?

Cheers,
_

sylas
20th December 2016, 09:34
I made a third project respecting this time the name "QtQuickCalculator". I included also the two files .cpp and .h about the viewers. Now the Application Output becomes exactly the same I had at the beginning of the thread. Here it is:
Starting /home/sylvain/build-QtQuickCalculator-Qt_5_5_1_in_PATH_qt5_invalid-Debug/QtQuickCalculator...
QML debugging is enabled. Only use this in a safe environment.
qrc:/main.qml:47:35: Unable to assign QQuickRectangle to QQuickAnchorLine
So there is apparently a syntax error. I added already to add left, right, bottom, top, center without any success.

anda_skoa
20th December 2016, 11:12
qrc:/main.qml:47:35: Unable to assign QQuickRectangle to QQuickAnchorLine
So there is apparently a syntax error. I added already to add left, right, bottom, top, center without any success.
Apparently you are back at your oridinal problem.

An anchor line property needs a compatible anchor line assignment, not an item.
There are vertical and horizontal lines http://doc.qt.io/qt-5/qtquick-positioning-anchors.html so compatible means a vertical line for a vertical anchor or a horizontal line for a horizontal anchor.

Cheers,
_

sylas
20th December 2016, 14:48
I don't find your reply. Maybe you consider it is enough with this thread. However I tell you that I repaired the error. I have now two projects which give me the same "application Output" message, the one I give on the title of my thread. I don't see how to repair this "syntax error". Cheers

sylas
20th December 2016, 17:02
Finished the problem with syntax. Iadded : .horizontalCenter. Finished the probllem with file not found. I wrote a new path. Now I have two projects one simple without vewers, the other with viewers. But no one shows any calculator upon 'run".
So it seems something is wrong in Main.cpp. I give you below the two codes:

//main.cpp of quickcalc project
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("/home/sylvain/quickcalc/main.qml"));
//viewer.showExpanded();//origin
viewer.show();
}

And the other:

//main.cpp of quickc project
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}

sylas
21st December 2016, 05:15
Apparently I don't see the calculator because there is nowhere any window in the main.qml . So I must construct one. isn't it ? How is it possible this calculator i so incomplete ? Regards

anda_skoa
21st December 2016, 10:11
Finished the problem with syntax. Iadded : .horizontalCenter.

We had that days ago already.



So it seems something is wrong in Main.cpp.

It is interesting how you find new ways of introducing problems.

First main.cpp is missing the application start, second main.cpp is OK but requires a QML file with a top level window element.


Apparently I don't see the calculator because there is nowhere any window in the main.qml . So I must construct one. isn't it ? How is it possible this calculator i so incomplete ?

I though you had it already working with qmlscene?

Cheers,
_