Vote count:
0
Now I have a Qt Quick Application, version 2.4, and I want to use C++ code to create an object to display some text in the Qt application.
I've tried reading countless Qt documentation, from the source themselves, most of which examples don't even compile on their own.
So I wanted help on display a C++ function returned value in the Qt Quick Application. All my code will be attached below, hope this isn't too much to ask and thanks for answering in advanced.
//MainForm.ui.qml, the area I want to display the text.
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1
Rectangle {
id: mainWindow
color: "#302a2a"
anchors.fill: parent
Rectangle {
id: equationAreaBackground
height: parent.height - 400
color: "#3f3737"
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
Text {
id: equation
color: "white"
text: qsTr("The Equation comes here")
anchors.fill: parent
font.pixelSize: 64
}
}
GroupBox {
id: mainTable
width: parent.width * 0.7
height: parent.height * 0.4
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: equationAreaBackground.bottom
anchors.topMargin: 0
/* Period One (1) */
Button {
id: elementH
x: 0
y: 0
width: parent.width/19
height: parent.height/7
text: qsTr("H")
}
And I want to display some C++ struct data on click of Button with ID: elementH. It is found in another file element.cpp, with header file: element.h.
File: Element Header
#ifndef ELEMENT
#define ELEMENT
struct element{};
#endif // ELEMENT
File: Element Source
#include <string>
#include "element.h"
struct element
{
// General Properties
string name;
string symbol;
int atomicNumber;
double atomicMass;
string category;
int group;
char block;
int period;
string electronConfig;
int valenceCount;
// Physical Properties
string color;
string phase;
double meltingPoint;
double boilingPoint;
// Others not yet necessary.
} elements[114];
void elementH()
{
// General Properties
elements[0].name = "Hydrogen";
elements[0].symbol = "H";
elements[0].atomicNumber = 1;
elements[0].atomicMass = 1.0079;
elements[0].category = "nonmetal";
elements[0].group = 1;
elements[0].block = "s";
elements[0].period = 1;
elements[0].electronConfig = "1";
elements[0].valenceCount = 1;
// Physical Properties
elements[0].color = "colorless";
elements[0].phase = "gas";
elements[0].meltingPoint = 13.99;
elements[0].boilingPoint = 20.271;
}
There is alot of other code involded, but it's mostly just repetition for other buttons. Thanks again.
display a c++ created object in a qt quick application
Aucun commentaire:
Enregistrer un commentaire