Qt-interest Archive, March 2007
QtScript and overloaded slots
Message 1 in thread
Hi,
I'm currently trying to make my first steps with QtScript.
I have created a prototype like this:
class MyObjectPrototype : public QObject, public QScriptable
{
Q_OBJECT
Q_PROPERTY(name READ name WRITE setName)
public:
MyObjectPrototype(QObject *parent = 0);
QString name() const;
void setName(const QString &);
public slots:
QScriptValue group(int index);
QScriptValue group(const QString &name);
};
The problem is that independently of whether I call myObject.group(42) or
myObject.group('XYZ') in the script, always the second slot is called,
i.e. the argument is passed as a QString. Is this a bug in QtScript or is
overloading of slots simply not possible?
Regards,
Bernd
--
[ signature omitted ]
Message 2 in thread
"Bernd Brandstetter" <bbrand@xxxxxxxxxx> wrote in message
news:200703251049.35183.bbrand@xxxxxxxxxxxxx
> Hi,
>
> I'm currently trying to make my first steps with QtScript.
> I have created a prototype like this:
>
> class MyObjectPrototype : public QObject, public QScriptable
> {
> Q_OBJECT
> Q_PROPERTY(name READ name WRITE setName)
>
> public:
> MyObjectPrototype(QObject *parent = 0);
>
> QString name() const;
> void setName(const QString &);
>
> public slots:
> QScriptValue group(int index);
> QScriptValue group(const QString &name);
> };
>
> The problem is that independently of whether I call myObject.group(42) or
> myObject.group('XYZ') in the script, always the second slot is called,
> i.e. the argument is passed as a QString. Is this a bug in QtScript or is
> overloading of slots simply not possible?
>
> Regards,
> Bernd
ECMAScript doesn't have overloading:
http://weblogs.asp.net/bleroy/archive/2005/02/15/Three-common-mistakes-in-JavaScript-_2F00_-EcmaScript.aspx
After all, script languages are not strongly typed, which is a requirement
for overloading.
Volker
--
[ signature omitted ]
Message 3 in thread
Bernd Brandstetter wrote:
> Hi,
>
> I'm currently trying to make my first steps with QtScript.
> I have created a prototype like this:
>
> class MyObjectPrototype : public QObject, public QScriptable
> {
> Q_OBJECT
> Q_PROPERTY(name READ name WRITE setName)
>
> public:
> MyObjectPrototype(QObject *parent = 0);
>
> QString name() const;
> void setName(const QString &);
>
> public slots:
> QScriptValue group(int index);
> QScriptValue group(const QString &name);
> };
>
> The problem is that independently of whether I call myObject.group(42) or
> myObject.group('XYZ') in the script, always the second slot is called,
> i.e. the argument is passed as a QString. Is this a bug in QtScript or is
> overloading of slots simply not possible?
>
> Regards,
> Bernd
>
Hi Bernd,
This has just been fixed. You should see the desired behavior in future
snapshots.
Regards,
Kent
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]