Results 1 to 8 of 8

Thread: How to create and insert a custom executable run configuration into my project?

  1. #1
    Join Date
    Sep 2013
    Posts
    32
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

    Question How to create and insert a custom executable run configuration into my project?

    In respect to your time, I will try to bee as brief as possible.

    My Goal: A plugin that does something along the lines of this:

    Qt Code:
    1. [...]
    2. void EchoPlugin::triggerAction() {
    3. ProjectExplorer::RunConfiguration* echo = ???;
    4. echo->setArguments("HelloWorld");
    5. echo->setExecutable("echo");
    6. ProjectExplorer::ProjectExplorerPlugin::currentProject()->activeTarget()->addRunConfiguration(echo);
    7. }
    8. [...]
    To copy to clipboard, switch view to plain text mode 

    Or if you are visually oriented, I am trying to create this:

    Ndi8Ty5.jpg

    With the executable being "echo" and the argument being "HelloWorld"

    From my research, the Classes in question are:
    - http://doc.qt.digia.com/qtcreator-ex...iguration.html
    - http://doc.qt.digia.com/qtcreator-ex...onfactory.html

    My issues:
    - I don't see a way to set the arguments.
    - The documentation does not coincide with my version of QtCreator (3.1.1), where both classes are actually found in the QtSupport namespace, not in ProjectExplorer.

    So I presume I am looking in the wrong place, and that I am probably not understanding how the run configurations are created.

    Now I do not claim any expertise in QtCreator's api, so if you feel the need to shout "RTFM!" to me, I will gladly take this under advisement. Otherwise, I offer my endless thanks to any one who takes the time to help me out with my ignorance.

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to create and insert a custom executable run configuration into my project?

    I consider myself both code-oriented and visually-oriented but I can't understand what you want to do. How does what you want to do differ from what Creator already provides?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2013
    Posts
    32
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to create and insert a custom executable run configuration into my project?

    Ha ha, I suppose I worded that ambiguously. Sorry

    I just want to create a run configuration for a current project that will execute a custom command, and that will show up here:

    zzrKvUM.png

    I obviously know how to do that through clicking through the qtcreator UI. I do not know how to do that however through using code, and I want to do it through code because my goal is to automate the creation of this custom executable run configuration.

    Does that make better sense?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to create and insert a custom executable run configuration into my project?

    So what exactly is the problem? It seems you should use IRunConfigurationFactory::createFactory() to get a factory for the run configuration you'd like to use and then call its create() method to create the run configuration.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2013
    Posts
    32
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to create and insert a custom executable run configuration into my project?

    /home/akiva/Autopilot/autopilotplugin.cpp:203: error: 'createFactory' is not a member of 'ProjectExplorer::IRunConfigurationFactory'
    ProjectExplorer::IRunConfigurationFactory::createF actory(ProjectExplorer::ProjectExplorerPlugin::cur rentProject()->activeTarget(),"wysotaiscool");
    ^

    Am I reading old documentation, or is there something obvious I am missing here?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to create and insert a custom executable run configuration into my project?

    I don't know if you are reading old documentation. I always look into the source code as Creator API often changes.

    Edit: Yes, looks like you are reading old docs.

    Here is how the class currently looks like:

    Qt Code:
    1. class PROJECTEXPLORER_EXPORT IRunConfigurationFactory : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit IRunConfigurationFactory(QObject *parent = 0);
    7. virtual ~IRunConfigurationFactory();
    8.  
    9. enum CreationMode {UserCreate, AutoCreate};
    10. virtual QList<Core::Id> availableCreationIds(Target *parent, CreationMode mode = UserCreate) const = 0;
    11. virtual QString displayNameForId(Core::Id id) const = 0;
    12.  
    13. virtual bool canCreate(Target *parent, Core::Id id) const = 0;
    14. RunConfiguration *create(Target *parent, Core::Id id);
    15. virtual bool canRestore(Target *parent, const QVariantMap &map) const = 0;
    16. RunConfiguration *restore(Target *parent, const QVariantMap &map);
    17. virtual bool canClone(Target *parent, RunConfiguration *product) const = 0;
    18. virtual RunConfiguration *clone(Target *parent, RunConfiguration *product) = 0;
    19.  
    20. static IRunConfigurationFactory *find(Target *parent, const QVariantMap &map);
    21. static IRunConfigurationFactory *find(Target *parent, RunConfiguration *rc);
    22. static QList<IRunConfigurationFactory *> find(Target *parent);
    23.  
    24. signals:
    25. void availableCreationIdsChanged();
    26.  
    27. private:
    28. virtual RunConfiguration *doCreate(Target *parent, Core::Id id) = 0;
    29. virtual RunConfiguration *doRestore(Target *parent, const QVariantMap &map) = 0;
    30. };
    To copy to clipboard, switch view to plain text mode 

    You should probably use find() and then find the factory you need in the list.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    Akiva (30th January 2015)

  8. #7
    Join Date
    Sep 2013
    Posts
    32
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to create and insert a custom executable run configuration into my project?

    I got a bit farther. Learned how to use Ctrl+k

    I checked out the factories available, but none of as far as I could tell, returned a class that could set arguments and the executable. The only class that allowed that was:

    Qt Code:
    1. #ifndef CUSTOMEXECUTABLERUNCONFIGURATION_H
    2. #define CUSTOMEXECUTABLERUNCONFIGURATION_H
    3.  
    4. #include "qtsupport_global.h"
    5.  
    6. #include <projectexplorer/localapplicationrunconfiguration.h>
    7.  
    8. #include <QVariantMap>
    9.  
    10. namespace ProjectExplorer { class Target; }
    11.  
    12. namespace QtSupport {
    13. namespace Internal { class CustomExecutableConfigurationWidget; }
    14.  
    15. class CustomExecutableRunConfigurationFactory;
    16.  
    17. class QTSUPPORT_EXPORT CustomExecutableRunConfiguration : public ProjectExplorer::LocalApplicationRunConfiguration
    18. {
    19. Q_OBJECT
    20. // the configuration widget needs to setExecutable setWorkingDirectory and setCommandLineArguments
    21. friend class Internal::CustomExecutableConfigurationWidget;
    22. friend class CustomExecutableRunConfigurationFactory;
    23.  
    24. public:
    25. explicit CustomExecutableRunConfiguration(ProjectExplorer::Target *parent);
    26. ~CustomExecutableRunConfiguration();
    27.  
    28. /**
    29.   * Returns the executable, looks in the environment for it and might even
    30.   * ask the user if none is specified
    31.   */
    32. QString executable() const;
    33.  
    34. /** Returns whether this runconfiguration ever was configured with an executable
    35.   */
    36. bool isConfigured() const;
    37.  
    38. RunMode runMode() const;
    39. QString workingDirectory() const;
    40. QString commandLineArguments() const;
    41.  
    42. QWidget *createConfigurationWidget();
    43.  
    44. ProjectExplorer::Abi abi() const;
    45.  
    46. QVariantMap toMap() const;
    47.  
    48. bool ensureConfigured(QString *errorMessage);
    49.  
    50. signals:
    51. void changed();
    52.  
    53. protected:
    54. CustomExecutableRunConfiguration(ProjectExplorer::Target *parent,
    55. CustomExecutableRunConfiguration *source);
    56. virtual bool fromMap(const QVariantMap &map);
    57. QString defaultDisplayName() const;
    58.  
    59. private:
    60. void ctor();
    61.  
    62. void setExecutable(const QString &executable);
    63. QString rawExecutable() const;
    64. void setCommandLineArguments(const QString &commandLineArguments);
    65. QString rawCommandLineArguments() const;
    66. void setBaseWorkingDirectory(const QString &workingDirectory);
    67. QString baseWorkingDirectory() const;
    68. void setUserName(const QString &name);
    69. void setRunMode(ProjectExplorer::LocalApplicationRunConfiguration::RunMode runMode);
    70. bool validateExecutable(QString *executable = 0, QString *errorMessage = 0) const;
    71.  
    72. QString m_executable;
    73. QString m_workingDirectory;
    74. QString m_cmdArguments;
    75. RunMode m_runMode;
    76. };
    77.  
    78. class CustomExecutableRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory
    79. {
    80. Q_OBJECT
    81.  
    82. public:
    83. explicit CustomExecutableRunConfigurationFactory(QObject *parent = 0);
    84. ~CustomExecutableRunConfigurationFactory();
    85.  
    86. QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent) const;
    87. QString displayNameForId(const Core::Id id) const;
    88.  
    89. bool canCreate(ProjectExplorer::Target *parent, const Core::Id id) const;
    90. bool canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const;
    91. bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *product) const;
    92. ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent,
    93. ProjectExplorer::RunConfiguration *source);
    94.  
    95. private:
    96. bool canHandle(ProjectExplorer::Target *parent) const;
    97.  
    98. ProjectExplorer::RunConfiguration *doCreate(ProjectExplorer::Target *parent, const Core::Id id);
    99. ProjectExplorer::RunConfiguration *doRestore(ProjectExplorer::Target *parent,
    100. const QVariantMap &map);
    101. };
    102.  
    103. } // namespace QtSupport
    104.  
    105. #endif // CUSTOMEXECUTABLERUNCONFIGURATION_H
    To copy to clipboard, switch view to plain text mode 

    The CustomExecutableRunConfigurationFactory is a friend of the class, but it does not seem to have any means to edit the arguments or executable. The same goes for the widget which takes a manual input.

    My issue (and feel free to yell "RTFM" at me for this) is that I can't figure out how to instantiate customExecutableRunConfiguration. Currently what I am thinking, is trying to create a class that inherits one of these classes, and write the method myself. I'm not sure if this is the proper way or if it will work.

    Sorry! And thanks for the help so far!

  9. #8
    Join Date
    Sep 2013
    Posts
    32
    Thanks
    9
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to create and insert a custom executable run configuration into my project?

    I just thought I would share my code for getting this to work

    Basically I went ahead and created a new class derived from LocalApplicationRunConfiguration

    Header:
    http://paste.ubuntu.com/10036050/

    Source:
    http://paste.ubuntu.com/10036058/

    I probably could have trimmed a bit more fat; I don't even know what ctor() is for.

    In any case, the implementation is very simple:
    http://paste.ubuntu.com/10036124/

    Thanks for your help, and I hope someone else benefits from this as well.

Similar Threads

  1. How to create executable in Ubuntu
    By WingFalcon in forum Installation and Deployment
    Replies: 2
    Last Post: 19th June 2013, 13:20
  2. Replies: 10
    Last Post: 6th February 2012, 16:42
  3. How to make my Qt project executable
    By mebingj in forum Installation and Deployment
    Replies: 1
    Last Post: 14th March 2011, 13:23
  4. How do I make my project executable file
    By theios_nikos in forum Newbie
    Replies: 8
    Last Post: 4th June 2010, 20:48
  5. How to create a standalone executable?
    By Ashish in forum Qt Programming
    Replies: 1
    Last Post: 25th January 2007, 15:04

Tags for this Thread

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.