qt


How to send a signal from one qml to another


I cannot find a way to communicate from one qml file to the other one. I know there are many ways to send signals from qml to C++ slots and reverse, but all my research about signals between two different qml files failed.
So I would be glad if someone can tell me, how I have to solve this problem.
First of all a little abstracted example to understand the problem in a better way...
The first QML in basics looks like that:
//MyQML1.qml
Rectangle
{
id: idMyRec1
signal mySignalFromQML1()
Button
{
id: idMyButton1
onClicked:
{
idMyRec1.mySignalFromQML1(); //to send the signal
}
}
}
The 2nd one looks like this:
//MyQML2.qml
Rectangle
{
id: idMyRec2
Text{
id: idMyText2
text: "Hello World!"
onMySignalFromQML1: //to receive the signal from the other qml
{
idMyText2.text = "Good Bye World!";
}
}
}
So this button should change the text in my 2nd QML to "Good Bye World!" when clicked...but this doesn't work...are there any other ways to send signals from QML to another QML?! Or am I doing something wrong?
You don't communicate between qml files, the QML file is just a prototype, you communicate between the object instances.
// Rect1.qml
Rectangle {
id: rect1
signal mySignal
Button {
onClicked: rect1.mySignal()
}
}
// Rect2.qml
Rectangle { // Rect1.qml
property alias text: txt.text
Text {
id: txt
}
}
And then you create the objects:
Rect1 {
onMySignal: r2.text = "Goodbye world!"
}
Rect2 {
id: r2
}
There are other ways to make a connection, however, connections happen between object instances, not qml files. The objects don't have to be in the same qml file too, but initially for simple things they will rarely be in different files.

Related Links

QListWidget collapsing/expanding of item's content
Adjust Brightness for qvideowidget inserted into the QGraphicsscene and QGraphicsView
Need to draw Transparent qimage that includes drawing of a circle using Qt
Need help connecting signal from thread to slot in GUI
Crash on using the opengl graphics system
UI problems when changing the screen-resolution
Test WinXP look on other platforms?
How to run thread from push button?
Qt Creator new tab not showing up when run
encoding file as base64 string in QT with XMLRPC
qlabel has wrong sizeHint() when wordwrap is enabled
Custom frame for QLineEdit
How to create an interactive tiled grouped list in PyQt?
BlackBerry10 Cascades: How to convert QObject to QVariant?
If Statements inside of OpenGL
QtCreator tricky project

Categories

HOME
rust
flask
shinyapps
seedstack
bokeh
paypal-ipn
visual-studio-2010
slider
ipv6
sentry
pyresttest
specifications
fasm
lapack
alljoyn
smooks
pm2
django-rq
max-msp-jitter
synthesis
nest-api
gravity
http-authentication
significance
bazaar
spring-ldap
uislider
ava
eclipse-emf
cell
react-dnd
data-collection
annotation-processing
tightvnc
location-services
listjs
markov-chains
busboy
stackpanel
nanogallery
fastlane
llvm-ir
assemblies
spring-restcontroller
angular-datatables
flipkart
react-intl
linq-to-excel
adblock
viewmodel
sonarqube5.2
sonicmq
watir-webdriver
nivo-slider
ptvs
stateless-session-bean
glassfish-4.1
polymaps
mifos
oci
perforce-integrate
strpos
persistent-object-store
vimperator
currency-exchange-rates
perceptron
cfwheels
canopy
ngcordova
shell-extensions
subview
htmltidy
berkeley-db-xml
code-complexity
forio-contour
fileshare
infinite
insertonsubmit
node.js-stream
apportable
ui-design
reentrancy
ntlmv2
user-forums
kaazing
prototypal-inheritance
differentiation
glassfish-esb
radscheduler
upshot
grails-validation
ognl
webresponse
active-record-query
jdownloader
outlook-2007-addin
j2mepolish
self-tracking-entities
bucket
sqlsitemapprovider
database-cloning
iphone-sdk-3.1.3
icon-language
error-detection

Resources

Encrypt Message