[Qt-creator] Send a message to the general message panel

Thomas Meyer public at meyer-thomas.com
Tue May 21 09:59:07 CEST 2013


Hi David,
thank you very much.
Meanwhile I found your solution by reading the source code of the 
'AnalyserBase' plugin.
 From 'AnalyzerUtils::findSymbolUnderCursor()':
...
         IEditor*editor=EditorManager::currentEditor();

     if  (!editor)

         return  0;

     TextEditor::ITextEditor  *textEditor  =  qobject_cast<TextEditor::ITextEditor  *>(editor);

     if  (!textEditor)

         return  0;

     TextEditor::BaseTextEditorWidget  *editorWidget  =  qobject_cast<TextEditor::BaseTextEditorWidget  *>(editor->widget());

     if  (!editorWidget)

         return  0;

     QPlainTextEdit  *ptEdit  =  qobject_cast<QPlainTextEdit  *>(editor->widget());

     if  (!ptEdit)

         return  0;
...

With 'insertPlainText()' it works too.
But I don't understand, why the 'qobject_cast' don't work for me. I have 
replaced it with 'dynamic_cast',
which works.

...
"Don't forget to add the TextEditor Plugin as a dependencie to your 
plugin :)"
...
Now, the 'qobject_cast' work for me. :-)

I have used the template to create the plugin and in the .pro file I find:
...
include($$QTCREATOR_SOURCES/src/qtcreatorplugin.pri)
include($$QTCREATOR_SOURCES/src/plugins/coreplugin/coreplugin.pri)
...
I have added here 
'include($$QTCREATOR_SOURCES/src/plugins/texteditor/texteditor.pri)'
and in the pluginspec.in:
<dependencyname=\"TextEditor\"version=\"$$QTCREATOR_VERSION\"/>
Is this enough? (It works.)
I found for example for the 'BinEditor' plugin an extra folder 
'bineditor_dependencies'
with the 'bineditor_dependencies.pri' file. Is this preferred or is it 
enough to write
it in the .pro file?

Is it possible to open a new 'Scratch Buffer' (temporäry file) before I 
send my text?

Thanks again,
     Thomas


Am 21.05.2013 08:41, schrieb David Schulz:
> Am 5/17/2013 11:45 PM, schrieb Thomas Meyer:
>> Hi,
>> how can I send a simple string (QString) from a plugin to the 'General
>> Messages' panel (or pane)
>> and how to the TextEditor (an opened text file)?
>
> Hi,
>
> you can use EditorManager::currentEditor() to get the editor.
> You receive an IEditor object, which you have to cast to ITextEditor.
> ITextEditor define the function insert(const QString& string)....
>
> sample code:
>
> if(IEditor*editor=EditorManager::currentEditor()){
> if(TextEditor::ITextEditor*textEditor=qobject_cast<TextEditor::ITextEditor*>(editor))
> textEditor->insert(QString("Helloworld"));
> }
> Don't forget to add the TextEditor Plugin as a dependencie to your 
> plugin :)
>
> BR,
> David
>
>> Where can I find some documentation about the 'communication' (sending
>> or receiving strings etc.)
>> between plugins and the different panes (panels?) and the TextEditor?
>>
>> Example:
>> I have build a simple plugin, which is a dialog with a button 'send
>> text' and should send
>> 'Hello world' to an opened text file. For 'debugging' I want to send
>> 'send text pressed'
>> to the 'General Messages' pane.
>>
>> Thanks,
>>       Thomas
>>
>>
>> _______________________________________________
>> Qt-creator mailing list
>> Qt-creator at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/qt-creator
>
>
>
> _______________________________________________
> Qt-creator mailing list
> Qt-creator at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/qt-creator

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20130521/469ee08c/attachment.html>


More information about the Qt-creator mailing list