One of the things I dont particularly enjoy is to transfer functions from .h (declaration) to .cpp (implementation), specifying the class scope and then creating open and close brackets. The whole process consumes time and I always thought that it can be automated quite easily in Qt Creator. Just wrote a plugin for Qt Creator that makes it possible.
Consider the following class definition below.
Select the function declarations from constructor all the way down to setCurrentColor(). Copy the code snippet using Ctrl+C. We now have a .cpp file for this class as shown below
With the ExpandDeclarations plugin installed, we can now hit the key-combination Ctrl+Shift+V, to get this dialog box
to get this
This one really saves time, I tell you.
You can grab a copy of the plugin from here: https://svn2.hosted-projects.com/vcreatelogic/VCLTools/QtCPlugins/. Username and password for read-only access is anonymous/anonymous. In the same location you can also find a plugin that provides a project wizard called “Qt Creator Plugin” that automatically generates a Qt Creator Plugin skeleton project for you.
You can now select File -> New project and select the “Qt Creator Plugin” project.
Answer some simple questions
And have a fully functional empty plugin project automatically generated :-).
These plugins are given away under LGPL. So you can use them for any purpose you see fit.
Comments
9 responses to “Expand Declarations in Qt Creator”
Me likey!
But the download-link requires authorisation. 😉
I had to use Delphi for a few years at work and the one thing I liked most was the Ctrl+Shift+C shortcut that auto-completed missing definitions for declarations of the class under the cursor. Does your plugin only work for new classes, or can I use it to autocomplete functions that I added after the others are already defined?
What language is it written in?
I’m currently not working on any project in Qt Designer, but will definitely check this out the next time I will.
yes.. the username and password for read-only access is anonymous.
One thing I have missed out in the article above is, you will need to select the function declarations and copy using Ctrl+C. Then use Ctrl+Shift+V to paste the definitions.
The plugin doesn’t auto-complete class definitions. It only pastes expanded definitions of copied function declarations.
This is so stunningly amazingly helpful 🙂 Thankyou 🙂
You should definitely forward this to the qtcreator team for inclusion in the base product.
Hey.. thanks.. I would love to do that.. I have just one more plugin to create and finish up, after which I will send the code to the Qt Creator team.
buglet?
The screenshot shows a default parameter being pasted into the cpp file (the = 0), that won’t compile AFAIK.
Is that a known issue? Might be nice to make your plugin remove those.
Thinking along, maybe you can add 2 checkboxes in your dialog (the one where you type the classname)
[X] add TODO in comments
[X] add Q_UNUSED for all parameters
Excellent work 🙂
Thomas
Re: buglet?
Thanks for the suggestion.. A colleague of mine is working on that now.. if you update from the SVN, you can see some progress with that.
cooool
я тоже так думаю иначе и не возможно!
Thank you very much! I was waiting for this time saver, because writing those method stubs by hand again, again and again is very frustrating.
good morning, this seems like a very nice plugin!
i just can’t get it to compile due to some compilation errors (pure virtual functions in QTCPluginProjectOptionsPageImpl, file ioptions.h l:52, 54, 55).
is this a bug or am i doing something wrong? i set QTC_SOURCE and QTC_BUILD correctly and ran qmake and make from the “QtCPlugins” directory.
using qt creator 2.0.1 sources on linux, qt4.7.0, x64.
thanks for any hints on what i’m doing wrong!