Solved Adding A Class In QtCreator
-
In QtCreator I add a class with QPlainTextEdit as the base class and I get the following;
#ifndef MYTEXTEDITOR_H
#define MYTEXTEDITOR_Hclass MyTextEditor : public QPlainTextEdit
{
public:
MyTextEditor();
};#endif // MYTEXTEDITOR_H
#include "mytexteditor.h"
MyTextEditor::MyTextEditor(){}
However, I need the something like the following:
#ifndef MYPLAINTEXTEDITOR_H
#define MYPLAINTEXTEDITOR_H#include <QObject>
#include <QPlainTextEdit>
#include "mainwindow.h"class MyPlainTextEditor : public QPlainTextEdit
{
Q_OBJECT
public:
MyPlainTextEditor(QWidget *parent = 0);
};#endif // MYPLAINTEXTEDITOR_H
MyPlainTextEditor::MyPlainTextEditor(QWidget *parent) : QPlainTextEdit(parent)
{}
My objective to promote the PlainTextEdit widget to MyPlainTextEditor. In the past I have added a MyCanvas class with QWidget as the base class to promote a QWidget and have never had to modify the code generated by QtCreator. If the base class is something other than QWidget, will I need to modify the code?
-
@ofmrew said in Adding A Class In QtCreator:
In the past I have added a MyCanvas class with QWidget as the base class to promote a QWidget and have never had to modify the code generated by QtCreator. If the base class is something other than QWidget, will I need to modify the code?
Yes, I also already noticed that the wizard is not clever enough to add the needed includes. (Btw:
#include <QPlainTextEdit>
should be enought.) So you will have to edit this template a bit to get a compilable source file.If you are annoyed about that, please file a bug at bugreports.qt.io
-
Hi
Yes it only support the shown includes.
In case of custom base class , no includes are added. -
So, if the base class is custom, i.e., not listed in the drop-down list, then it is up to the programmer to finish the prototype and the constructor.
-
@ofmrew
well its faster to use QWidget and just change to the wanted type.
If you use custom base class, it seems it does not call base class in ctor init list.test::test(QWidget *parent) : QWidget(parent) <<< missing with custom
If you wish, they are easy to change
C:\Qt\Tools\QtCreator\share\qtcreator\templates\wizards\classes\cpp -
@mrjj Thanks. I will look into that.