Creating a custom project wizard in Qt Creator



  • Hello everybody,

    I'm writing because got really stuck with creating a custom project wizard, particularly adding new item in 'New file or project...' menu section.

    I took some thoughts from here, some pieces from documentation and some other resources with relatively fresh info.

    The main idea I have been trying to implement up until now is to create new class in some way derived from IWizardFactory (tried directly derived, derived from BaseFileWizardFactory, from CustomProjectWizard and CustomWizardMetaFactory), add it to the PluginManager pool (with addAutoReleasedObject) and according to the documentation PM will do the rest.

    Adding to the PM pool - no problem, I can see it from printing names of objects from PM pool.
    But adding entry to the menu doesn't happen and my factory doesn't show up in the output of IWizardFactory::allWizardFactories.

    The question is: what am I missing/doing wrong? My code of the latest attempt is below:

    SomeProjectWizardFactory.h

    #include <projectexplorer/customwizard/customwizard.h>
    #include "Someprojectwizard.h"
    
    class SomeProjectWizardFactory : public ProjectExplorer::CustomWizardMetaFactory<SomeProjectWizard>
    {
      Q_OBJECT
    public:
      SomeProjectWizardFactory();
    };
    

    SomeProjectWizardFactory.cpp

    #include "Someprojectwizard.h"
    
    SomeProjectWizardFactory::SomeProjectWizardFactory()
      : ProjectExplorer::CustomWizardMetaFactory<SomeProjectWizard>(Core::IWizardFactory::ProjectWizard)
    {}
    

    SomeProjectWizard.h

    #include <projectexplorer/customwizard/customwizard.h>
    
    class SomeProjectWizard : public ProjectExplorer::CustomProjectWizard
    {
      Q_OBJECT
    public:
      SomeProjectWizard();
    };
    

    SomeProjectWizard.cpp

    #include "Someprojectwizard.h"
    
    SomeProjectWizard::SomeProjectWizard()
      : ProjectExplorer::CustomProjectWizard()
    {
      setDisplayName("Some");
      setCategory("Some");
      setDescription("Some description");
      setDisplayCategory("Some");
      setId(Core::Id("Some.Id"));
    }
    

    SomePlugin.cpp

    bool SomePlugin::initialize(const QStringList &arguments, QString *errorString)
    {
        ...
        SomeProjectWizard *factory = new SomeProjectWizard();
        addAutoReleasedObject(factory);
        ...
    


  • After some research I found the answer to my problem.

    The key point is that after this commit what is written on the IWizardFactory documentation page is not applicable anymore as now you should use following code to register your custom project wizard:

    // someplugin.cpp, someplugin::initialize
    Core::IWizardFactory::registerFactoryCreator([]() -> QList<Core::IWizardFactory *> {
        return QList<Core::IWizardFactory *> { new SomeProjectWizard };
      });
    

    I believe that IWizardFactory documentation page should be updated :)


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You can check the bug report system and open a bug report against the Qt Creator project for that.

    Even better, if you know where the missing documentation should, you could consider providing a patch for Qt Creator's sources.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.