<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Change text with PySide and qml, not working for me...]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I am trying to change the text from "Hello world" to just "Hi". I want to do it by pressing the button "Press me!" that rotates the words "Hello world". I have changed the original example to also change the words not just rotate the text. But the word changing part does not work... What am I doing wrong?</p>
<p dir="auto">Error message: "Error: Insufficient arguments"<br />
It is in the qml part at this line:<br />
helloText.text = changeText.doChange()</p>
<p dir="auto"><a href="http://main.py" target="_blank" rel="noopener noreferrer nofollow ugc">main.py</a><br />
@<br />
#!/usr/bin/python2.7</p>
<h1>Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).</h1>
<h1>All rights reserved.</h1>
<h1>Contact: PySide Team (pyside at <a href="http://openbossa.org" target="_blank" rel="noopener noreferrer nofollow ugc">openbossa.org</a>)</h1>
<h1></h1>
<h1>This file is part of the examples of PySide: Python for Qt.</h1>
<p dir="auto">...</p>
<h1>$QT_END_LICENSE$</h1>
<p dir="auto">from PySide import QtCore, QtGui, QtDeclarative</p>
<p dir="auto">class RotateValue(QtCore.QObject):<br />
def <strong>init</strong>(self):<br />
super(RotateValue,self).<strong>init</strong>()<br />
self.r = 0</p>
<pre><code>QtCore.Slot(result=int)
def val(self):
</code></pre>
<p dir="auto">self.r = self.r + 90<br />
return self.r</p>
<p dir="auto">class ChangeText(QtCore.QObject):<br />
def <strong>init</strong>(self):<br />
super(ChangeText,self).<strong>init</strong>()<br />
self.s = "Hi"</p>
<pre><code># if a slot returns a value the return value type must be explicitly
# defined in the decorator
QtCore.Slot("QString")
def doChange(self):
    return self.s
</code></pre>
<p dir="auto">if <strong>name</strong> == '<strong>main</strong>':<br />
import sys</p>
<pre><code>app = QtGui.QApplication(sys.argv)

view = QtDeclarative.QDeclarativeView()

rotatevalue = RotateValue()
changeText = ChangeText()
timer = QtCore.QTimer()
timer.start(2000)

conrotate = view.rootContext()
conrotate.setContextProperty("rotatevalue", rotatevalue)

context = view.rootContext()
context.setContextProperty("changeText", changeText)
view.setSource(QtCore.QUrl('view.qml'))
view.show()

sys.exit(app.exec_())
</code></pre>
<p dir="auto">@</p>
<p dir="auto">view.qml</p>
<p dir="auto">@/*<br />
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).<br />
** All rights reserved.<br />
** Contact: PySide Team (pyside at <a href="http://openbossa.org" target="_blank" rel="noopener noreferrer nofollow ugc">openbossa.org</a>)<br />
**<br />
** This file is part of the examples of PySide: Python for Qt.<br />
...<br />
$QT_END_LICENSE$<br />
*/</p>
<p dir="auto">import Qt 4.7</p>
<p dir="auto">Rectangle {<br />
id: page</p>
<pre><code>width: 500; height: 200
color: "lightgray"

Text {
    id: helloText
    text: "Hello world!"
    anchors.horizontalCenter: page.horizontalCenter
    y: 30
    font.pointSize: 24; font.bold: true
}


Rectangle {
    id: button
    width: 150; height: 40
    color: "darkgray"
    anchors.horizontalCenter: page.horizontalCenter
    y: 120
    MouseArea {
        id: buttonMouseArea
        objectName: "buttonMouseArea"
        anchors.fill: parent
        onClicked: {
            helloText.rotation = rotatevalue.val()
</code></pre>
<p dir="auto">// next line generates the error<br />
helloText.text = changeText.doChange()<br />
}<br />
}<br />
Text {<br />
id: buttonText<br />
text: "Press me!"<br />
anchors.horizontalCenter: button.horizontalCenter<br />
anchors.verticalCenter: button.verticalCenter<br />
font.pointSize: 16;<br />
}<br />
}<br />
}@</p>
]]></description><link>https://forum.qt.io/topic/3386/change-text-with-pyside-and-qml-not-working-for-me</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Jul 2026 18:35:27 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/3386.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 Jan 2011 21:36:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Change text with PySide and qml, not working for me... on Tue, 01 Feb 2011 14:34:11 GMT]]></title><description><![CDATA[<p dir="auto">Thank you, I have got it to work now :)</p>
]]></description><link>https://forum.qt.io/post/73438</link><guid isPermaLink="true">https://forum.qt.io/post/73438</guid><dc:creator><![CDATA[BadOmen]]></dc:creator><pubDate>Tue, 01 Feb 2011 14:34:11 GMT</pubDate></item><item><title><![CDATA[Reply to Change text with PySide and qml, not working for me... on Mon, 31 Jan 2011 17:25:51 GMT]]></title><description><![CDATA[<p dir="auto">I learned it from the examples provided with PySide. There are basically 2 solutions for this:</p>
<ol>
<li>
<p dir="auto">Create a QObject with a property and in QML use this property. Whenever you change the value, you emit "changed" signal and this will instruct the QML UI to react upon it. This is the preferred way of doing it.</p>
</li>
<li>
<p dir="auto">You can call a JavaScript function in your QML from Python. In the function you can do whatever you want. This is needed in some cases, where you explicitly need to call a function not just change a property.</p>
</li>
</ol>
<p dir="auto">If you need more help, let me know.</p>
]]></description><link>https://forum.qt.io/post/73279</link><guid isPermaLink="true">https://forum.qt.io/post/73279</guid><dc:creator><![CDATA[jech]]></dc:creator><pubDate>Mon, 31 Jan 2011 17:25:51 GMT</pubDate></item><item><title><![CDATA[Reply to Change text with PySide and qml, not working for me... on Fri, 28 Jan 2011 16:42:39 GMT]]></title><description><![CDATA[<p dir="auto">Jech: Michael found my problem.</p>
<p dir="auto">What I am doing... good question =) I am just playing around and trying to get a basic understanding of the communication.</p>
<p dir="auto">I have now changed the doChange function and added a integer attribute to the class. It uses the Class attribute to count how many times I have pressed the button. Not much of use but I have learned how to use a python object in qml.:<br />
@  QtCore.Slot(str,result="QString")<br />
def doChange(self,prevMsg):<br />
if self.i == 0:<br />
self.originalText= prevMsg<br />
self.i +=1<br />
return self.originalText + str(self.i)@<br />
The next step I will take is to find a way to change any qml element from python. Is there any good tutorials for that?</p>
]]></description><link>https://forum.qt.io/post/73101</link><guid isPermaLink="true">https://forum.qt.io/post/73101</guid><dc:creator><![CDATA[BadOmen]]></dc:creator><pubDate>Fri, 28 Jan 2011 16:42:39 GMT</pubDate></item><item><title><![CDATA[Reply to Change text with PySide and qml, not working for me... on Fri, 28 Jan 2011 13:01:03 GMT]]></title><description><![CDATA[<p dir="auto">I absolutely don't understand what you're trying to do here. Do you want to send data from QML to Python or from Python to QML? It looks to me that you totally mixed it.</p>
<p dir="auto">I have quite a lot of experiences with both, so tell me what you're trying to do and I'm certain I will be able to help you.</p>
]]></description><link>https://forum.qt.io/post/73084</link><guid isPermaLink="true">https://forum.qt.io/post/73084</guid><dc:creator><![CDATA[jech]]></dc:creator><pubDate>Fri, 28 Jan 2011 13:01:03 GMT</pubDate></item><item><title><![CDATA[Reply to Change text with PySide and qml, not working for me... on Fri, 28 Jan 2011 10:37:11 GMT]]></title><description><![CDATA[<p dir="auto">lol thanx man!</p>
<p dir="auto">I know I tried that earlier but then I must have had some other error in the code that messed it up :)<br />
( they do it in the original example but with a int =)  )</p>
<p dir="auto">It would have taken me a long time figuring that out :D</p>
]]></description><link>https://forum.qt.io/post/73055</link><guid isPermaLink="true">https://forum.qt.io/post/73055</guid><dc:creator><![CDATA[BadOmen]]></dc:creator><pubDate>Fri, 28 Jan 2011 10:37:11 GMT</pubDate></item><item><title><![CDATA[Reply to Change text with PySide and qml, not working for me... on Fri, 28 Jan 2011 00:09:55 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">From looking at <a href="http://www.pyside.org/docs/pyside/PySide/QtCore/Slot.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://www.pyside.org/docs/pyside/PySide/QtCore/Slot.html</a>, it seems like <em>QtCore.Slot("QString")</em> will create a slot wanting a QString parameter (rather than a QString return value). Does changing it to something like <em>QtCore.Slot(result='QString')</em> work for you?</p>
<p dir="auto">Regards,<br />
Michael</p>
]]></description><link>https://forum.qt.io/post/73032</link><guid isPermaLink="true">https://forum.qt.io/post/73032</guid><dc:creator><![CDATA[mbrasser]]></dc:creator><pubDate>Fri, 28 Jan 2011 00:09:55 GMT</pubDate></item></channel></rss>