19
Jan
I've recently added a handy command line tool for introspecting the methods in Smoke libraries. Although it is mainly aimed at people using Smoke based language bindings, I think it might be more generally useful and worth describing to a wider audience.
Show all the methods in the QPoint class:
$ smokeapi QPoint
QPoint::QPoint()
QPoint::QPoint(const QPoint&)
QPoint::QPoint(int, int)
bool QPoint::isNull() const
...
Note that the qtcore module is always opened by default. Here only 'QPoint' is given as a class name, but you can specify more than one class
Next, show all the methods in the qtgui module with 'popup' in their name:
$ smokeapi -r qtgui -m popup
QAbstractItemView* QCompleter::popup() const
void QMenu::popup(const QPoint&)
void QMenu::popup(const QPoint&, QAction*)
QRect& QStyleOptionComboBox::popupRect() const
QToolButton::ToolButtonPopupMode QToolButton::popupMode() const
The '-r qtgui' option means open the libsmokeqtgui library - for KDE 4.4 SC release we added the ability to dynamically open and load the Smoke libraries, and it so that means the tool doesn't need to be linked in advance to any libraries to be searched. The '-m popup' option means match methods with the regular expression pattern 'popup'. No class names are specified and so all classes in the target Smoke libraries are searched. If you use '-i' in conjuction with the '-m' open it will do a case insensitive match.
Find all the signals emitted by KAction, including inherited ones:
$ smokeapi -r kdeui -p -m ^signal KAction
signal void QObject::destroyed()
signal void QObject::destroyed(QObject*)
signal void QAction::changed()
signal void QAction::hovered()
signal void QAction::toggled(bool)
signal void QAction::triggered()
signal void QAction::triggered(bool)
signal void KAction::authorized(KAuth::Action*)
signal void KAction::globalShortcutChanged(const QKeySequence&)
signal void KAction::triggered(Qt::MouseButtons, Qt::KeyboardModifiers)
The '-p' options means include the parent classes of any classes specified. If you want to search for slots you can use a pattern of '^slot' to match them.
One limitation is that the Smoke libraries don't included templated methods, and so they we be missed out. Other than that I find it very handy to quickly search the apis without needing to go to Qt Assistant or browse the KDE api docs
I also added a similar tool called 'jsmokeapi' to the JSmoke bindings which gives the method signatures in a JavaScript format.
- richard dale's blog
- Login or register to post comments
Comments
Maybe I suck
It could be me just sucking at Google but the problem I had when I was considering using SMOKE for my last project was the lack of a homepage or any real step-by-step documentation. Is this still the case? I ended up using QtScriptGenerator instead as a result.
Apologies if not, it was a few months ago.
Re: Maybe I suck
No, you don't suck, but maybe I do! Docs for JSmoke are completely lacking.
There are examples that I have ported from the Qt Labs QtScript bindings which worked fine with Qt 4.5, but not with Qt 4.6. A bug in Qt 4.6 where it largely ignores the reply from QScriptClass::propertyFlags, means that setting Q_PROPERTYs on classes which have been subclassed in JavaScript doesn't work. So there are some non-working examples and no docs.. Hmm
If you want documentation about creating bindings with Smoke there is a Smoke TechBase page. But we really need to have some info about the JSmoke JavaScript bindings up on TechBase too.
Haha, you certainly don't
Haha, you certainly don't suck!
Can SMOKE be used for non-Qt/non-KDE C++ files/classes, or does it rely on MOC stuff?
If so, it seems a shame that it's hidden away on Planet KDE and Techbase. It would be cool to have a standalone project homepage with perhaps a wiki for examples and the like and links to the source and perhaps binary downloads for non-Linux platforms.
Re: Can SMOKE be used for
"Can SMOKE be used for non-Qt/non-KDE C++ files/classes, or does it rely on MOC stuff?
There are no dependencies on Qt in the generated Smoke libaries. It doesn't depend on the moc at all. The bindings generator is written using the Qt libs though as it was derived from the qtscriptgenerator and KDevelop parser. I used Smoke to create Ruby bindings for the Wt C++ web development library, which doesn't use Qt and it worked fine.
"If so, it seems a shame that it's hidden away on Planet KDE and Techbase. It would be cool to have a standalone project homepage with perhaps a wiki for examples and the like and links to the source and perhaps binary downloads for non-Linux platforms."
To turn it into more of a stand alone project I think we would need to create generic runtimes for a variety of languages that were free of Qt dependencies. Although the Smoke libraries themselves don't have to have Qt dependencies, you still need a runtime for your language to do anything useful. We don't currently have enough people to be able to do that, along with creating a suitable web site and extra documentation. So for now I think TechBase, writing blogs and having discussions on the kdebindings mailing list and IRC channel is good enough.