Results 1 to 1 of 1

Thread: Custom file template for QtCreator

  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Custom file template for QtCreator

    Hello. With QtCreator, I can create a new source and header file combined with a shell class easily, by going File -> "New File or Project" -> C++-> C++ Class.

    In my current project, I have a shell class (inherited from another class, with virtual functions that need to be created) I have to create over and over.
    I want to create a custom template file, just like QtCreator's "C++ Class" template, to create my own template file.

    How can I do this? I checked the documentations, and as far as I can see, I can only figure out how to (by some very complicated methods) create project templates, not Source + Header file templates added to my existing project.

    Has anyone done this before?


    Added after 50 minutes:


    Nevermind, this time I figured it out. Here's how it's done:

    Go to: ...\QtSDK\QtCreator\share\qtcreator\templates\wiza rds
    Create a new folder for your template. Add your source and header files, and copy the .xml file from the 'listmodel' folder (in the 'wizards' folder).

    Your .xml file must be named 'wizard.xml' (not wizard_sample.xml, which will be ignored).
    Edit that file to suit your needs. My file looks like this:


    <--- licensing notice from Qt --->
    <wizard version="1" kind="class"
    id="R.Plain C++" category="B.CustomClasses">
    <icon>AdventureFar.png</icon>
    <description>Creates an inheritted GameState class for AdventureFar.</description>
    <displayname>AdventureFar GameState</displayname>;
    <displaycategory>Custom Classes</displaycategory>
    <files>
    <file source="source.cpp" target="%ClassName%.%CppSourceSuffix%" openeditor="true"/>
    <file source="header.h" target="%ClassName%.%CppHeaderSuffix%" openeditor="true"/>
    </files>
    <!-- Create parameter wizard page -->
    <fieldpagetitle>GameState parameters</fieldpagetitle>
    <fields>
    <field name="ClassName">
    <fieldcontrol class="QLineEdit" validator="^[a-zA-Z0-9_]+$" defaulttext="MyGameState" />
    <fielddescription>Class name:</fielddescription>
    </field>
    </fields>
    </wizard>
    Note that in your template source and header files, any field variables you use (such as the 'ClassName' field in the xml file above), if you have them wrapped in '%' symbols, like this: %MyFieldName%, will be replaced with that field.

    Also, if you have :l after it, like this: %MyFieldName:l% it'll be replaced with the lowercase version of the text. Likewise, :u like %MyFieldName:u% will be replaced with the uppercase version.

    Basically, that's all that's required. You have to restart QtCreator to get the template to show up in the "Create New" template window, but it'll automaticly scan and find your wizard.xml file.
    Last edited by ComServant; 8th March 2012 at 04:45.

  2. The following user says thank you to ComServant for this useful post:

    s200999900 (9th March 2012)

Similar Threads

  1. Replies: 1
    Last Post: 26th November 2010, 08:22
  2. Replies: 2
    Last Post: 25th August 2010, 09:25
  3. Replies: 4
    Last Post: 25th June 2010, 09:21
  4. QtCreator on mac. How to add custom widgets?
    By MuzZviman in forum Qt Tools
    Replies: 0
    Last Post: 24th May 2010, 02:20
  5. Replies: 9
    Last Post: 15th October 2009, 10:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.