QtCreator plugin output should be printed in the child process's qtcreator application output pane



  • I have a qtcreator plugin developed to perform a copyright analysis check of given input source files ( Source files can be passed as input). I have added a menu option "Check copyright" in Qtcreator Tools option and I call a perl script program to perform the analysis. I need to print the output of the perl script program in the application output pane of Qtcreator. The output is printed in the application output window but it gets printed in the qtcreator output pane from where the plugin is launched from.
    Instead I want it to be printed in the child window of qt creator's application output pane.

    To elaborate in detail:
    When I build and run the plugin code, a new version of Qtcreator is launched and on performing the copyright option in the child process, I find the output printed in the application output pane of Qt creator (parent window ) from where the plugin was executed.

    I also copied the plugin.so to the qtcreator's plugin library path. Once I open the qtcreator from terminal and execute the plugin operation, I find the output printed in the terminal in this case.

    Expected output:
    Once the plugin is copied to plugin library path, I want the output to be printed in the same QtCreator application output window wherever the plugin operation was performed. In my case, the output is printed in the parent window.

    Please let me know what is to be done here.

    Source:
    bool MyPluginPlugin::initialize(const QStringList &arguments, QString *errorString)
    {
    auto action = new QAction(tr("Check Copyright"), this);
    Core::Command *cmd = Core::ActionManager::registerAction(action, Constants::ACTION_ID,
    Core::Context(Core::Constants::C_GLOBAL));
    connect(action, &QAction::triggered, this, &MyPluginPlugin::triggerAction);

    }

    void MyPluginPlugin::triggerAction()
    {
    QProcess p;

    p.start("perl chkCpyright.pl");
    p.waitForFinished(-1);
    
    QByteArray p_stdout1 =  p->readAllStandardOutput();
    QString p_stdout=  QString::fromLatin1 (p_stdout1);
    
    QTextStream out(stdout);
    out << QString(p_stdout) << endl;
    

    }



  • Hi, instead of using stdout, you can try to display the perl output in the "General Messages" window pane in Qt Creator.

    First:
    #include <coreplugin/messagemanager.h>

    Then you can use this call to display a string (multiline works ok):
    Core::MessageManager::write(p_stdout);



  • @Veepee
    [The following may not matter if you use whatever @hskoglund has just posted, I don't know anything about that. Plus I have to confess that I know nothing about "plugins"...]

    I don't understand what you're saying is wrong with your current code? Are you saying that the Perl script produces output but you fail to capture it? In that case, do you know that its output is going to stdout rather than to stderr??



  • @hskoglund said in QtCreator plugin output should be printed in the child process's qtcreator application output pane:

    Core::MessageManager::write(p_stdout);

    This works like a charm. Thank you so much



  • This forum is not actively monitored by developers, so for technical questions like these you might want to move over to the mailing lists and IRC. That's where all the Qt project internal communication happens and all developers hang out there.

    For Qt Creator in particular, please consider to switch to the qt-creator mailing list (http://lists.qt-project.org/mailman/listinfo/qt-creator) or the #qt-creator channel on the freenode.net IRC network.



  • Is there a possibility to get the output printed asynchronously in Qt Creator ?
    i.e : I want the output from script to be printed in output pane here directly instead of waiting until the script execution completes and then writing it as a single chunk.


  • Qt Champions 2017

    @Veepee said in QtCreator plugin output should be printed in the child process's qtcreator application output pane:

    Is there a possibility to get the output printed asynchronously in Qt Creator ?
    i.e : I want the output from script to be printed in output pane here directly instead of waiting until the script execution completes and then writing it as a single chunk.

    That should work the usual way: connect a slot printing the output to the readyRead signal and remove the waitForFinished() line from your function.

    Make sure you enter the event loop again and do not block in your triggerAction() function.

    Note: you should change the stack variable QProcess p to a member variable then.



  • @aha_1980
    Great, this worked. Thank you.

    connect(&p, SIGNAL(readyRead()), this, SLOT(handleReadyRead()));
     p.start(processArg);
    

    void handleReadyRead()
    {
    QByteArray p_stdout = p.readAllStandardOutput();
    QString s_stdout= QString::fromLatin1 (p_stdout) ;
    Core::MessageManager::write(s_stdout);
    }


Log in to reply
 

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