[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-bindings
Subject:    Re: [Kde-bindings] Qt, Qyoto buttons work intermediately
From:       Linuxoid Oz <linuxoidoz () yahoo ! com ! au>
Date:       2010-02-16 21:52:56
Message-ID: 971068.50140.qm () web111015 ! mail ! gq1 ! yahoo ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I've read that thing about the signals/slots and that was exactly what I was trying \
to do (at least I thought that was exactly what they said). Here's an example from a \
Qt Address Book tutorial:

 connect(nextButton, SIGNAL(clicked()), this, SLOT(next()));

As the QMessageBox needs a parent reference, 'this' is fine for the MainWindow. This \
is my slot:

QObject.Connect(btnAbout, Qt.SIGNAL("clicked()"), mainwin, 
Qt.SLOT("ShowAbout(mainwin, page)"));

First, the Qt one doesn't have these " ", so I thought it might be a Qyoto thing. \
'this' is a reference to MainWindow. In my StartWindow, 'mainwin' is a reference to \
the MainWindow. If I use a slot in MainWindow I pass the slot a 'this' reference as \
in the example. If I use a slot in the StartWindow I pass it a reference to \
MainWindow as 'mainwin'.

Are you saying if I declare the SecondWindow class as inherited from :QWidget I \
should then pass the reference to itself as 'this' rather than a reference to the \
MainWindow?

In the StartWindow the QMessageBox also needs a parent reference, that's why I pass \
'mainwin'  - reference to parent MainWindow. What do you mean by passing a type \
rather than a variable? How do you pass a type if you need to pass a reference to the \
parent window? If I pass anything else it complains that that reference doesn't exist \
in the current context.


Yes. You didn't understand how signals and slots work. This explains it all: 
http://doc.trolltech.com/4.6/signalsandslots.html .

Short summery: This line
QObject.Connect(btnAbout, Qt.SIGNAL("clicked()"), mainwin, 
Qt.SLOT("ShowAbout(mainwin, page)"));
connects to a method (slot) ShowAbout() which takes two arguments: one of type 
mainwin, one of type page. There are two reasons why this won't work:

1. The signal doesn't provide any parameters, but the slot does. How is this 
supposed to work?
2. You give a method signature to the SLOT method, i.e. mainwin and page are 
expected to be types, not variables. But there is no type called 'mainwin' and 
there is also no type called 'page'. Both are variables. But this is not how 
signals and slots work. SIGNAL and SLOT expect _signatures_, not method call 
expressions.

Furthermore, you can only define slots in QObject subclasses. Otherwise you 
have to use delegate connections. (QObject.Connect(sender, SIGNAL(/*signal*/), 
delegate { /* ... */ });)



      __________________________________________________________________________________
 Yahoo!7: Catch-up on your favourite Channel 7 TV shows easily, legally, and for free \
at PLUS7. www.tv.yahoo.com.au/plus7


[Attachment #5 (text/html)]

<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: \
inherit;">I've read that thing about the signals/slots and that was exactly what I \
was trying to do (at least I thought that was exactly what they said). Here's an \
example from a Qt Address Book tutorial:<br><br> connect(nextButton, \
SIGNAL(clicked()), this, SLOT(next()));<br><br>As the QMessageBox needs a parent \
reference, 'this' is fine for the MainWindow. This is my \
slot:<br><br>QObject.Connect(btnAbout, Qt.SIGNAL("clicked()"), mainwin,  \
Qt.SLOT("ShowAbout(mainwin, page)"));<br><br>First, the Qt one doesn't have these " \
", so I thought it might be a Qyoto thing. 'this' is a reference to MainWindow. In my \
StartWindow, 'mainwin' is a reference to the MainWindow. If I use a slot in \
MainWindow I pass the slot a 'this' reference as in the example. If I use a slot in \
the StartWindow I pass it a reference to MainWindow as 'mainwin'.<br><br>Are you \
saying if I declare the SecondWindow class as inherited from :QWidget I should then \
pass the reference to itself as 'this' rather than a reference to the \
MainWindow?<br><br>In the StartWindow the QMessageBox also needs a parent reference, \
that's why I pass 'mainwin'&nbsp; - reference to parent MainWindow. What do you mean \
by passing a type rather than a variable? How do you pass a type if you need to pass \
a reference to the parent window? If I pass anything else it complains that that \
reference doesn't exist in the current context.<br> <br><blockquote \
style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: \
5px;"><div class="plainMail">Yes. You didn't understand how signals and slots work. \
This explains it all: <br><a href="http://doc.trolltech.com/4.6/signalsandslots.html" \
target="_blank">http://doc.trolltech.com/4.6/signalsandslots.html</a> .<br><br>Short \
summery: This line<br>QObject.Connect(btnAbout, Qt.SIGNAL("clicked()"), mainwin, \
<br>Qt.SLOT("ShowAbout(mainwin, page)"));<br>connects to a method (slot) ShowAbout() \
which takes two arguments: one of type <br>mainwin, one of type page. There are two \
reasons why this won't work:<br><br>1. The signal doesn't provide any parameters, but \
the slot does. How is this <br>supposed to work?<br>2. You give a method signature to \
the SLOT method, i.e. mainwin and page are <br>expected to be types, not variables. \
But there is no type called 'mainwin' and <br>there is also no type called 'page'. \
Both are variables. But this  is not how <br>signals and slots work. SIGNAL and SLOT \
expect _signatures_, not method call <br>expressions.<br><br>Furthermore, you can \
only define slots in QObject subclasses. Otherwise you <br>have to use delegate \
connections. (QObject.Connect(sender, SIGNAL(/*signal*/), <br>delegate { /* ... */ \
});)<br></div></blockquote></td></tr></table><br>



      &nbsp;



_______________________________________________
Kde-bindings mailing list
Kde-bindings@kde.org
https://mail.kde.org/mailman/listinfo/kde-bindings


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic