Montag, 16. Juli 2012

I can haz QMetaObject?

I was asked if it was possible to define signals and slots from inside qling. While I hadn't thought about that until then, the solution seemed simple enough and I went ahead and implemented it.

I am just searching for Q_OBJECT in the user's input and, if found, invoke moc, pipe the users input into moc's stdin and, if successful, pass moc's output back into the interpreter. While this solution definitely has its flaws (atm there is no check if the user's input was correct, if the macro is inside a class-definition of if the class is actually derived from QObject), it serves as a starting point. And it's kinda fun :)

This "dumb" method is needed for the run-off-the-mill cling (SVN trunk). I am working on a patch to (hopefully soon) be included in cling that will allow me to install an ASTConsumer and a preprocessor-callback. The ASTConsumer allows me to monitor if a subclass of QObject was defined and the preprocessor-callback allows me to monitor if the Q_OBJECT macro was expanded. If both conditions are met, moc will be invoked. This will certainly be the correct way to go, until then the dumbed-down string-matching version will do its job... kinda... :)
Oh, almost forgot to add a screenshot:



Cheers, Thomas

Keine Kommentare:

Kommentar veröffentlichen