Hello,
I'm trying to implement the "Address Book Example" with Qt-Ruby.
http://doc.qt.nokia.com/4.7-snapshot/itemviews-addressbook.html
The problem that I face is that in the AddressWidget class, there are
two "addEntry" methods (one without parameter and the other with two
parameters) and they are both slots.
In Ruby, I think we can't have two addEntry methods in the same class.
So, what is the solution? Only one addEntry method with a hash as only
parameter?
Thank you.
--
Posted via http://www.ruby-forum.com/.
|
|
0
|
|
|
|
Reply
|
Arturo
|
11/20/2010 4:32:03 PM |
|
I'm not completely sure, but this should work:
- define a method called add_entry which takes two optional arguments
having
nil as default value. Inside the method, you check whether one of the
arguments is nil or not and choose the correct behaviour accordingly:
def add_entry name = nil, address = nil
if name and address
#behave as the addEntry(QString, QString) function
else
#behave as the addEntry() function
end
end
- define two slots, one with no arguments and one with two arguments:
slots 'add_entry()', 'add_entry(QString,QString)'
Note that this won't work with signals: there can be only one signal
with a
given name, regardless of its signature.
I hope this helps
Stefano
--
Posted via http://www.ruby-forum.com/.
|
|
0
|
|
|
|
Reply
|
Stefano
|
11/21/2010 9:25:43 AM
|
|
Thank you for the reply!
Stefano Crocco wrote in post #962907:
> I'm not completely sure, but this should work:
> - define a method called add_entry which takes two optional arguments
> having
> nil as default value. Inside the method, you check whether one of the
> arguments is nil or not and choose the correct behaviour accordingly:
>
> def add_entry name = nil, address = nil
> if name and address
> #behave as the addEntry(QString, QString) function
> else
> #behave as the addEntry() function
> end
> end
Indeed, it works! The simplest solution is often the better! Thank you!
> - define two slots, one with no arguments and one with two arguments:
>
> slots 'add_entry()', 'add_entry(QString,QString)'
By the way, I have some questions again.
- In this example, they use the QPair class. It seems that this class
isn't implemented in Qt-Ruby (as for the array and hash classes). So I
use an array of size two instead and it seems to work fine. Is it the
way to do it or do I have to use an other Ruby class to use QPair?
- If I want to create a slot that have a Ruby hash as parameter, which
QT class must I use in the slot declaration (QHash, QMap, ...)?
> Note that this won't work with signals: there can be only one signal
> with a
> given name, regardless of its signature.
I didn't knew that, thank you. Is it specific to Qt-Ruby or it is the
same in C++?
> I hope this helps
>
> Stefano
Yes it helps, thanks again!
--
Posted via http://www.ruby-forum.com/.
|
|
0
|
|
|
|
Reply
|
Arturo
|
11/21/2010 12:20:37 PM
|
|
On Sunday 21 November 2010 21:20:37 Arturo Bonechi wrote:
> Thank you for the reply!
>
> Stefano Crocco wrote in post #962907:
> > I'm not completely sure, but this should work:
> > - define a method called add_entry which takes two optional arguments
> > having
> > nil as default value. Inside the method, you check whether one of the
> > arguments is nil or not and choose the correct behaviour accordingly:
> >
> > def add_entry name = nil, address = nil
> >
> > if name and address
> >
> > #behave as the addEntry(QString, QString) function
> >
> > else
> >
> > #behave as the addEntry() function
> >
> > end
> >
> > end
>
> Indeed, it works! The simplest solution is often the better! Thank you!
>
> > - define two slots, one with no arguments and one with two arguments:
> >
> > slots 'add_entry()', 'add_entry(QString,QString)'
>
> By the way, I have some questions again.
> - In this example, they use the QPair class. It seems that this class
> isn't implemented in Qt-Ruby (as for the array and hash classes). So I
> use an array of size two instead and it seems to work fine. Is it the
> way to do it or do I have to use an other Ruby class to use QPair?
Yes, using an array here is correct. Everytime you see a collection
looking
like a list in C++ (for example, whenever they use QStringList), you
need to
replace it with an array in qtruby
> - If I want to create a slot that have a Ruby hash as parameter, which
> QT class must I use in the slot declaration (QHash, QMap, ...)?
>
I don't think you can do that. It seems that neither QHash nor QMap are
implemented in qtruby, and passing a native ruby hash doesn't seem to
work. In my opinion, being restricted to using C++ types is one of the
most serious weaknesses of qtruby. In your case, I think the best option
would be to declare both signal with a string argument, then convert the
hash to a string (using Marshal or YAML) before emitting the signal and
converting it back in the slot.
> > Note that this won't work with signals: there can be only one signal
> > with a
> > given name, regardless of its signature.
>
> I didn't knew that, thank you. Is it specific to Qt-Ruby or it is the
> same in C++?
No, it's another limitation of qtruby. It's caused by the fact that
calling
signals creates a method taking a number of parameters according to the
signature you specified. Calling it again with the same name attempts to
create another method with the same name and (maybe) a different number
of
arguments. Since ruby doesn't allow to have different methods with the
same
name, however, this effectively overwrites the first method.
Stefano
--
Posted via http://www.ruby-forum.com/.
|
|
0
|
|
|
|
Reply
|
Stefano
|
11/21/2010 1:35:49 PM
|
|
Stefano Crocco wrote in post #962925:
> Yes, using an array here is correct. Everytime you see a collection
> looking
> like a list in C++ (for example, whenever they use QStringList), you
> need to
> replace it with an array in qtruby
Ok, thank you.
> I don't think you can do that. It seems that neither QHash nor QMap are
> implemented in qtruby, and passing a native ruby hash doesn't seem to
> work. In my opinion, being restricted to using C++ types is one of the
> most serious weaknesses of qtruby. In your case, I think the best option
> would be to declare both signal with a string argument, then convert the
> hash to a string (using Marshal or YAML) before emitting the signal and
> converting it back in the slot.
So, I suppose that I need to do this conversion with arrays too... If
that is the price to pay it's Ok for me.
> No, it's another limitation of qtruby. It's caused by the fact that
> calling
> signals creates a method taking a number of parameters according to the
> signature you specified. Calling it again with the same name attempts to
> create another method with the same name and (maybe) a different number
> of
> arguments. Since ruby doesn't allow to have different methods with the
> same
> name, however, this effectively overwrites the first method.
Ok, thanks for the explanation.
One last question :
In the Qt-Ruby declaration of signals and slots, the C++ keywords
"const" and "&" are sometimes added, but they aren't added in the code
when a slot is "connected" (only the C++ type is mentioned).
For example :
...
slots 'a_slot(const QString&)'
...
connect an_object, SIGNAL('a_signal(QString)'), self,
SLOT('a_slot(QString)')
...
Must I add those keywords to the declaration or are they optional? When
do I know that I have to add them?
Thank you.
--
Posted via http://www.ruby-forum.com/.
|
|
0
|
|
|
|
Reply
|
Arturo
|
11/21/2010 3:05:32 PM
|
|
On Monday 22 November 2010 00:05:32 Arturo Bonechi wrote:
> Stefano Crocco wrote in post #962925:
> > I don't think you can do that. It seems that neither QHash nor QMap are
> > implemented in qtruby, and passing a native ruby hash doesn't seem to
> > work. In my opinion, being restricted to using C++ types is one of the
> > most serious weaknesses of qtruby. In your case, I think the best option
> > would be to declare both signal with a string argument, then convert the
> > hash to a string (using Marshal or YAML) before emitting the signal and
> > converting it back in the slot.
>
> So, I suppose that I need to do this conversion with arrays too... If
> that is the price to pay it's Ok for me.
Yes, you need to do that also for arrays, except when they stand for a
QStringList (and maybe some other specialized class).
> One last question :
> In the Qt-Ruby declaration of signals and slots, the C++ keywords
> "const" and "&" are sometimes added, but they aren't added in the code
> when a slot is "connected" (only the C++ type is mentioned).
>
> For example :
> ...
> slots 'a_slot(const QString&)'
> ...
> connect an_object, SIGNAL('a_signal(QString)'), self,
> SLOT('a_slot(QString)')
> ...
>
> Must I add those keywords to the declaration or are they optional? When
> do I know that I have to add them?
No, you don't need them. The only modifier you need is the * for
pointers. For example,
slots 'my_slot(QObject*)'
would be correct, while
slots 'my_slot(QObject)'
would give you an error
Stefano
--
Posted via http://www.ruby-forum.com/.
|
|
0
|
|
|
|
Reply
|
Stefano
|
11/21/2010 4:43:28 PM
|
|
Stefano Crocco wrote in post #962967:
>
> Yes, you need to do that also for arrays, except when they stand for a
> QStringList (and maybe some other specialized class).
>
>> One last question :
>> In the Qt-Ruby declaration of signals and slots, the C++ keywords
>> "const" and "&" are sometimes added, but they aren't added in the code
>> when a slot is "connected" (only the C++ type is mentioned).
>>
>> For example :
>> ...
>> slots 'a_slot(const QString&)'
>> ...
>> connect an_object, SIGNAL('a_signal(QString)'), self,
>> SLOT('a_slot(QString)')
>> ...
>>
>> Must I add those keywords to the declaration or are they optional? When
>> do I know that I have to add them?
>
> No, you don't need them. The only modifier you need is the * for
> pointers. For example,
>
> slots 'my_slot(QObject*)'
>
> would be correct, while
>
> slots 'my_slot(QObject)'
>
> would give you an error
>
> Stefano
Ok, thanks for all this details!
Back to code, now!
Thank you.
--
Posted via http://www.ruby-forum.com/.
|
|
0
|
|
|
|
Reply
|
Arturo
|
11/21/2010 4:57:29 PM
|
|
|
6 Replies
142 Views
(page loaded in 0.091 seconds)
Similiar Articles: writing robust software? - comp.lang.c++.moderatedThere is a book "C++ Coding Guidelines" which contains ... Menzl Non-spammers may respond to my email address ... can be solved by careful programming, so that's a red ... data structures on shared memory? - comp.unix.programmer ...As a example, let's say my structure handles data in this ... the first things exec() does is discard the old address ... exceed way longer my knowldege, is there any book or ... Glut disadvantage... - comp.graphics.api.opengl... then why does the redbook use it? > The red book is very ... For example if your're using C++ as programming language ... are multiplatform solutions for this like glut, qt ... rewrite glRotate? - comp.graphics.api.openglWolfgang Draxinger -- E-Mail address works, Jabber ... In the Red Book there's a own chapter about it ... Vertex Array Implementation - comp.graphics.api.opengl rewrite ... improve strlen - comp.lang.asm.x86Here's a typical strlen() implementation in C int strlen ... thx all i learn more with you than all book ... text; const char* base = 0; meta::intp address ... Please Reproduce: PHP 5.2 -> 5.3 Windows Apache2.2 crash - comp ...-- ===== Remove the "x" from my email address Jerry Stuckle ... person, but being someone who has written a book ... Python's implementation of OOP is also quite different from ... pbuffers - comp.graphics.api.openglWolfgang Draxinger -- E-Mail address works, Jabber ... For example, to create the pbuffer as an RGBA 2D texture ... What is the best book on OpenGL? - comp.graphics.api ... Simple code encryption (xor) problem - comp.lang.asm.x86 ...The payload gets the address of caption and text ... working - comp.soft-sys.matlab... btw, the red book example ... attach my code [ jxorcrypt.cpp] /* A simple implementation ... [comp.publish.cdrom] CD-Recordable FAQ, Part 1/4 - comp.publish ...Archive-name: cdrom/cd-recordable/part1 Posting-Frequency: monthly Last-modified: 2008/10/09 Version: 2.71 Send corrections and updates to And... Vertex arrays and unexpected behaviour - comp.graphics.api.opengl ...... is similar what I said earlier - in the above example ... of the terrain" come from? That's a LOD in my book. ... QT_terr has no material or lighting system (need's an ... Qt 4.7: Address Book Example - Club des développeurs Qt ...Qt 4.7: Address Book Example ... Ruby & Rails; Web sémantique ... explained in MainWindow's implementation. Each table view in the address book is ... Qt (framework) - Wikipedia, the free encyclopediaQt ( / ˈ k juː t / "cute", or unofficially as Q-T cue-tee ... The complete book (PDF in a ZIP); suitable for those who ... Articles with example C++ code; 1992 software; Nokia software ... 7/4/2012 1:26:53 PM
|