Qt-jambi-interest Archive, September 2006
Re: Signals and Slots Lack Compile Time Error Checking
Message 1 in thread
Chris Verwymeren wrote:
> Jambi's current implementation of the signals and slots mechanism
> suffers from a lack of compile time error checking.
>
> For example, all of these code fragments compile without errors, however
> only the first fragment is correct.
>
> cancelButton.clicked.connect(this, "close()");
>
> cancelButton.clicked.connect(this, "clse()");
>
> cancelButton.clicked.connect(this, "close(boolean)");
>
> No notification is given unless the application attempt to execute that
> section of code. Executing the code results in the exception "Exception
> in thread "main" com.trolltech.qt.QNoSuchSlotException Slot not found".
>
> Would it be possible to have the exception generated when the code is
> being compiled?
Hi Chris,
Having compile time checking of these strings is not possible,
however... Qt has worked with strings for signals/slots connections for
over 10 years and its proven that this kind of error does not happen
that often, and when it does you just fix the syntax and continue your
coding. The code that does connections is usually in the initialization
phase which is always executed, so this error will often occur
immediatly when you start your app, making it easy to detect and fix in
practice.
There is a suggestion in the bug parade to the Java language to
introduce a compile time way of getting Method objects from a class
(like function references in C++), though I can't find it again now ;-)
This would remove the theoretical problem.
Another thing that is more likely to happen is that tools like eclipse
and intellij get extended code completion that shows the proper
signatures in the connect statement, and when you have code completion,
you'll probably never misstype like that again ;-)
best regards,
Gunnar
Message 2 in thread
I think you mean this rfc:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5014235
I also like compile time checking, and not only to protect me against
typing errors but also to be able to search for references and refactor.
I know Eclipse is able to search in strings, but that is awfully slow,
and does not work for connections to methods with arguments.
-----Original Message-----
From: Gunnar Sletta [mailto:gunnar@xxxxxxxxxxxxx]
Sent: Friday, September 01, 2006 8:53
To: Chris Verwymeren
Cc: qt-jambi-interest@xxxxxxxxxxxxx
Subject: Re: Signals and Slots Lack Compile Time Error Checking
Chris Verwymeren wrote:
> Jambi's current implementation of the signals and slots mechanism
> suffers from a lack of compile time error checking.
>
> For example, all of these code fragments compile without errors,
however
> only the first fragment is correct.
>
> cancelButton.clicked.connect(this, "close()");
>
> cancelButton.clicked.connect(this, "clse()");
>
> cancelButton.clicked.connect(this, "close(boolean)");
>
> No notification is given unless the application attempt to execute
that
> section of code. Executing the code results in the exception
"Exception
> in thread "main" com.trolltech.qt.QNoSuchSlotException Slot not
found".
>
> Would it be possible to have the exception generated when the code is
> being compiled?
Hi Chris,
Having compile time checking of these strings is not possible,
however... Qt has worked with strings for signals/slots connections for
over 10 years and its proven that this kind of error does not happen
that often, and when it does you just fix the syntax and continue your
coding. The code that does connections is usually in the initialization
phase which is always executed, so this error will often occur
immediatly when you start your app, making it easy to detect and fix in
practice.
There is a suggestion in the bug parade to the Java language to
introduce a compile time way of getting Method objects from a class
(like function references in C++), though I can't find it again now ;-)
This would remove the theoretical problem.
Another thing that is more likely to happen is that tools like eclipse
and intellij get extended code completion that shows the proper
signatures in the connect statement, and when you have code completion,
you'll probably never misstype like that again ;-)
best regards,
Gunnar
Message 3 in thread
Daan de Wit wrote:
> I think you mean this rfc:
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5014235
> I also like compile time checking, and not only to protect me against
> typing errors but also to be able to search for references and refactor.
> I know Eclipse is able to search in strings, but that is awfully slow,
> and does not work for connections to methods with arguments.
Hadn't seen that one, but here are a few others ;-)
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4810162
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5043025
-
Gunnar ;-)