PDA

View Full Version : View possible in the design mode and qmlscene but not at the end or"run"



sylas
22nd December 2016, 19:36
Hi all ! No problem during the building. At the end of "run" the message of Application Output is: Button is not a type (in main.qml).. This looks like a nonsense. I give you below the two codes of "Button.qml" and "main.qml". The main.cpp is constructed by QtCreator. This project comes from a book.There are many days I try to finish this project, without success.I hope somebody will help me.

//button.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 }
}
}



Next

//main.qml
import QtQuick 2.3
import QtQuick.Window 2.2

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
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottomMargin: 20
spacing: 20

Button { //Button is not a type
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)
}

}

}

d_stranz
22nd December 2016, 20:56
Is your file named "button.qml" or "Button.qml"? Makes a difference, you know.

sylas
22nd December 2016, 21:02
The name of the file : button.qml Thank you very much for your reply

d_stranz
23rd December 2016, 17:35
Well then, QML is going to be looking for a type named "button", not "Button". Rename your file to be consistent with QML conventions.

sylas
23rd December 2016, 18:22
I deleted button.qml and then added Button.qml. There was an error of mine, but the application Output is now:
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.
For the views unfortunately they are the same as before. We must find another error. Thanks

d_stranz
23rd December 2016, 23:26
I don't know what else you are doing wrong, but in Button.qml, you are importing QtQuick 2.0, and in main.qml you are importing QtQuick 2.3. If you are writing your own code, then you should import the same version everywhere to ensure there aren't any conflicts.

sylas
24th December 2016, 07:10
I put QtQuick 2.5 in the two files. Same results. It is really very strange that last year, with O.S Linux 14.4 this worked well. Now with my 16.4 it doesn't. It looks as if a plugin is missing. Isn't it ? ?

Added after 54 minutes:

There is a difference between the Design picture on my book (in the Library it writes about Items) while in the Design picture of my screen it speeks of QML Types.

anda_skoa
24th December 2016, 13:32
I deleted button.qml and then added Button.qml. There was an error of mine, but the application Output is now:
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.
For the views unfortunately they are the same as before. We must find another error. Thanks

There is no error and you have not provided any description of what is wrong.


I don't know what else you are doing wrong, but in Button.qml, you are importing QtQuick 2.0, and in main.qml you are importing QtQuick 2.3. If you are writing your own code, then you should import the same version everywhere to ensure there aren't any conflicts.

That shouldn't matter, otherwise one would have to constantly update ones files.

Cheers,
_

sylas
24th December 2016, 16:45
I repeat. This calculator, last year, worked very well. Since I changed my O.S., I lost it, and now impossible to realize it. The big difference between the screenshot of my book and the picture I have on my screen is: Library shows "items" on my book and on my screen library speeks of QML. Here I send you a little screenshot of my screen:
12264

anda_skoa
25th December 2016, 11:47
Since you've started a new thread and wasted all context, there is nothing to even guess why it is not working elsewhere.

Apparently you have a program that starts fine given the application output you've posted.

Not sure what the screenshot of the QtQuick designer should tell us, but you've said the QML files work with qmlscene, so they should be ok.

Cheers,
_

sylas
25th December 2016, 15:15
The only thing I can try now is to delete my QCreator and install a new one. I remind you that after my new O.S., Quick did not work with new QCreator I installed from Ubuntu Software Center. Someone of your forum indicated me to install qtdeclarative5-dev and qml-module-qtquick2. After that quick projects became possible.
So you are the only one who can indicate me what complete QtCreator I must install. I am Linux user (O.S. 16.04) and I prefer use my terminal for installing.
Must I uninstall the two little "plugings" too, before I install my new QtCreator, I hope you will indicate to me. Thank you very much. Cheers

anda_skoa
26th December 2016, 11:26
If qmlscene works it is unlikely that there is something missing in the installation.

Also your program runs without error, again an indication that the installation is ok.

You have given no indication of what the problem is.

Cheers,
_

sylas
26th December 2016, 12:34
The problem is that last year, with the ancient O.S. the calculator appeared at the end of "run". To-day no. I give below below the code of main.cpp. Maybe that there is the solution:

//main.cpp
#include <QGuiApplication>//origin
//#include <QQmlEngine>
//#include <QQuickImageProvider>
//#include <QImageWriter>
//#include <QAccessiblePlugin>
#include <QQmlApplicationEngine>//origin

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

QQmlApplicationEngine engine;//origin
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

return app.exec();
}

anda_skoa
27th December 2016, 11:53
You are using a QQmlApplicaiton engine, yet your top level QtQuick element is not a Window.

Seems like you took QML code from a QQuickView based program and mixed it with a QQmlEngine based main.

I highly doubt that worked with any previous Qt version.

Cheers,
_

sylas
27th December 2016, 17:14
So the error is in main.cpp. You should be very kind to rectify that code, and inform me. Unfortunately I am not experienced enough with Qt quick. Many thanks
Cheers

anda_skoa
28th December 2016, 10:07
Didn't one of your postings in one of the other threads already have the code for QQuickView?

Cheers,
_

sylas
28th December 2016, 10:24
Even with the code of code-bundle I am unable to finish. It seems however so simple since the Design view is pretty well.. I give you the two codes (mine above, code from bundle below)

//main.cpp
#include <QtGui/QGuiApplication>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);

QGuiApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/quick/main.qml"));
viewer.showExpanded();

return app.exec();
}
/*
//From code bundle
#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();

return app.exec();
}
*/

anda_skoa
29th December 2016, 17:03
How on earth is this related to the previous code?

Are you just randomly posting code?

Cheers,
_

sylas
30th December 2016, 05:40
What a relief*! Yesterday I saw the calculator at the end of «*run*». At first I deleted my Qt Creator of Ubuntu Software Center and I replaced it by the Qt Creator I got via the terminal. I have two projects (quick and QtQuickCalculator). The last has 3 files more than the other*: qtquick2applicationviewer.h , same name with .cpp, same name with .pri. It is this big project that works well. The only error it had is the path in the line*:
viewer.setMainQmlfile(QStringLiteral(«*/home/sylvain/QtQuickCalculator/main.qml*»))*;
I think the short project «*quick*» will work well if we put the calculator inside a button or window, exactly as does qmlscene. If you help me I think we will make that »quick*» project work as well as the other big project*!