I have 2 qml files:
1 is main.qml when user write his name and click go button send the name to main.cpp file and main.cpp send the name statment to
2 showName.qml and hide main.qml and open showName.qml
how to do that?
main.qml
import QtQuick 2.3
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
Window {
visible: true
TextField {
id: aName
placeholderText: qsTr("Enter your name")
}
Button {
id: go
y: 50
text: qsTr("Go")
}
}
import QtQuick 2.3
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
Window {
visible: true
TextField {
id: aName
placeholderText: qsTr("Enter your name")
}
Button {
id: go
y: 50
text: qsTr("Go")
}
}
To copy to clipboard, switch view to plain text mode
showName.qml
import QtQuick 2.0
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
Item {
Text {
id: aName
text: qsTr( aName )// aName come from main.cpp
font.pixelSize: 12
}
}
import QtQuick 2.0
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
Item {
Text {
id: aName
text: qsTr( aName )// aName come from main.cpp
font.pixelSize: 12
}
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.
load(QUrl(QStringLiteral
("qrc:/main.qml")));
// i want here to get aName from main.cpp, send aName to showName.qml, hide main.qml and show showName.qml
return app.exec();
}
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
// i want here to get aName from main.cpp, send aName to showName.qml, hide main.qml and show showName.qml
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks