cannot convert argument 1 from 'QWidget *' to 'QObject *'
-
Please bear with me and let me explain my problem.
I have a piece of code that uses QSyntaxHighlighter Class ( https://doc.qt.io/qt-5.15/qsyntaxhighlighter.html#QSyntaxHighlighter)
In the code, a class named GlslHighlighter is defined in glslHighlighter.h as follows:
class GlslHighlighter: public QSyntaxHighlighter { public: GlslHighlighter(); virtual ~GlslHighlighter(); void setDocument( QTextDocument *textdoc , const e_GlslLanguageType language); ............. }
constructor in glslHighlighter.cpp is as follows:
GlslHighlighter::GlslHighlighter() : QSyntaxHighlighter(static_cast<QWidget*>(NULL)) , m_language(GLSLT_Common) { }
Now, the constructor for QSyntaxHighlighter in Qt documentation is defined as follows:
QSyntaxHighlighter::QSyntaxHighlighter(QTextDocument *parent) QSyntaxHighlighter::QSyntaxHighlighter(QObject *parent)
( https://doc.qt.io/qt-5.15/qsyntaxhighlighter.html#QSyntaxHighlighter-1)
Even in Qt4 documentation it is as follows:
QSyntaxHighlighter::QSyntaxHighlighter ( QObject * parent ) QSyntaxHighlighter::QSyntaxHighlighter ( QTextDocument * parent ) QSyntaxHighlighter::QSyntaxHighlighter ( QTextEdit * parent )
(https://het.as.utexas.edu/HET/Software/html/qsyntaxhighlighter.html#QSyntaxHighlighter)
When I am trying to compile GlslHighlighter.cpp, i get the error message as follows:
\glslhighlighter.cpp(40): error C2664: 'QSyntaxHighlighter::QSyntaxHighlighter(const QSyntaxHighlighter &)': cannot convert argument 1 from 'QWidget *' to 'QObject *'
Now, here is my doubt. Isn't argument 1 of the type QWidget* in violation of the definition of the constructor of the class GlslHighlighter? I don't see any way to fix this error without altering the argument type in the definition file ie glslHighlighter.h
-
Please bear with me and let me explain my problem.
I have a piece of code that uses QSyntaxHighlighter Class ( https://doc.qt.io/qt-5.15/qsyntaxhighlighter.html#QSyntaxHighlighter)
In the code, a class named GlslHighlighter is defined in glslHighlighter.h as follows:
class GlslHighlighter: public QSyntaxHighlighter { public: GlslHighlighter(); virtual ~GlslHighlighter(); void setDocument( QTextDocument *textdoc , const e_GlslLanguageType language); ............. }
constructor in glslHighlighter.cpp is as follows:
GlslHighlighter::GlslHighlighter() : QSyntaxHighlighter(static_cast<QWidget*>(NULL)) , m_language(GLSLT_Common) { }
Now, the constructor for QSyntaxHighlighter in Qt documentation is defined as follows:
QSyntaxHighlighter::QSyntaxHighlighter(QTextDocument *parent) QSyntaxHighlighter::QSyntaxHighlighter(QObject *parent)
( https://doc.qt.io/qt-5.15/qsyntaxhighlighter.html#QSyntaxHighlighter-1)
Even in Qt4 documentation it is as follows:
QSyntaxHighlighter::QSyntaxHighlighter ( QObject * parent ) QSyntaxHighlighter::QSyntaxHighlighter ( QTextDocument * parent ) QSyntaxHighlighter::QSyntaxHighlighter ( QTextEdit * parent )
(https://het.as.utexas.edu/HET/Software/html/qsyntaxhighlighter.html#QSyntaxHighlighter)
When I am trying to compile GlslHighlighter.cpp, i get the error message as follows:
\glslhighlighter.cpp(40): error C2664: 'QSyntaxHighlighter::QSyntaxHighlighter(const QSyntaxHighlighter &)': cannot convert argument 1 from 'QWidget *' to 'QObject *'
Now, here is my doubt. Isn't argument 1 of the type QWidget* in violation of the definition of the constructor of the class GlslHighlighter? I don't see any way to fix this error without altering the argument type in the definition file ie glslHighlighter.h
@Alcor your GlsHighlighter class is set up wrong, from the get go.
said in cannot convert argument 1 from 'QWidget *' to 'QObject *':
class GlslHighlighter: public QSyntaxHighlighter
{
public:
GlslHighlighter();
virtual ~GlslHighlighter();void setDocument(
QTextDocument *textdoc
, const e_GlslLanguageType language);.............
}class GlslHighlighter: public QSyntaxHighlighter { Q_OBJECT public: GlslHighlighter(QObject *parent = nullptr); virtual ~GlslHighlighter(); void setDocument( QTextDocument *textdoc , const e_GlslLanguageType language); ............. > }
in *.cpp
GlslHighlighter::GlslHighlighter(QObject *parent) : QSyntaxHighlighter(parent) , m_language(GLSLT_Common) { }
That fixes your issue, you don't need to modify any calling code and the now added Q_Object macro will prevent future pain and misery
-
Please bear with me and let me explain my problem.
I have a piece of code that uses QSyntaxHighlighter Class ( https://doc.qt.io/qt-5.15/qsyntaxhighlighter.html#QSyntaxHighlighter)
In the code, a class named GlslHighlighter is defined in glslHighlighter.h as follows:
class GlslHighlighter: public QSyntaxHighlighter { public: GlslHighlighter(); virtual ~GlslHighlighter(); void setDocument( QTextDocument *textdoc , const e_GlslLanguageType language); ............. }
constructor in glslHighlighter.cpp is as follows:
GlslHighlighter::GlslHighlighter() : QSyntaxHighlighter(static_cast<QWidget*>(NULL)) , m_language(GLSLT_Common) { }
Now, the constructor for QSyntaxHighlighter in Qt documentation is defined as follows:
QSyntaxHighlighter::QSyntaxHighlighter(QTextDocument *parent) QSyntaxHighlighter::QSyntaxHighlighter(QObject *parent)
( https://doc.qt.io/qt-5.15/qsyntaxhighlighter.html#QSyntaxHighlighter-1)
Even in Qt4 documentation it is as follows:
QSyntaxHighlighter::QSyntaxHighlighter ( QObject * parent ) QSyntaxHighlighter::QSyntaxHighlighter ( QTextDocument * parent ) QSyntaxHighlighter::QSyntaxHighlighter ( QTextEdit * parent )
(https://het.as.utexas.edu/HET/Software/html/qsyntaxhighlighter.html#QSyntaxHighlighter)
When I am trying to compile GlslHighlighter.cpp, i get the error message as follows:
\glslhighlighter.cpp(40): error C2664: 'QSyntaxHighlighter::QSyntaxHighlighter(const QSyntaxHighlighter &)': cannot convert argument 1 from 'QWidget *' to 'QObject *'
Now, here is my doubt. Isn't argument 1 of the type QWidget* in violation of the definition of the constructor of the class GlslHighlighter? I don't see any way to fix this error without altering the argument type in the definition file ie glslHighlighter.h
@Alcor since you pass a nullptr to the base class what's the problem to pass a QObject nullptr?
-
Please bear with me and let me explain my problem.
I have a piece of code that uses QSyntaxHighlighter Class ( https://doc.qt.io/qt-5.15/qsyntaxhighlighter.html#QSyntaxHighlighter)
In the code, a class named GlslHighlighter is defined in glslHighlighter.h as follows:
class GlslHighlighter: public QSyntaxHighlighter { public: GlslHighlighter(); virtual ~GlslHighlighter(); void setDocument( QTextDocument *textdoc , const e_GlslLanguageType language); ............. }
constructor in glslHighlighter.cpp is as follows:
GlslHighlighter::GlslHighlighter() : QSyntaxHighlighter(static_cast<QWidget*>(NULL)) , m_language(GLSLT_Common) { }
Now, the constructor for QSyntaxHighlighter in Qt documentation is defined as follows:
QSyntaxHighlighter::QSyntaxHighlighter(QTextDocument *parent) QSyntaxHighlighter::QSyntaxHighlighter(QObject *parent)
( https://doc.qt.io/qt-5.15/qsyntaxhighlighter.html#QSyntaxHighlighter-1)
Even in Qt4 documentation it is as follows:
QSyntaxHighlighter::QSyntaxHighlighter ( QObject * parent ) QSyntaxHighlighter::QSyntaxHighlighter ( QTextDocument * parent ) QSyntaxHighlighter::QSyntaxHighlighter ( QTextEdit * parent )
(https://het.as.utexas.edu/HET/Software/html/qsyntaxhighlighter.html#QSyntaxHighlighter)
When I am trying to compile GlslHighlighter.cpp, i get the error message as follows:
\glslhighlighter.cpp(40): error C2664: 'QSyntaxHighlighter::QSyntaxHighlighter(const QSyntaxHighlighter &)': cannot convert argument 1 from 'QWidget *' to 'QObject *'
Now, here is my doubt. Isn't argument 1 of the type QWidget* in violation of the definition of the constructor of the class GlslHighlighter? I don't see any way to fix this error without altering the argument type in the definition file ie glslHighlighter.h
@Alcor your GlsHighlighter class is set up wrong, from the get go.
said in cannot convert argument 1 from 'QWidget *' to 'QObject *':
class GlslHighlighter: public QSyntaxHighlighter
{
public:
GlslHighlighter();
virtual ~GlslHighlighter();void setDocument(
QTextDocument *textdoc
, const e_GlslLanguageType language);.............
}class GlslHighlighter: public QSyntaxHighlighter { Q_OBJECT public: GlslHighlighter(QObject *parent = nullptr); virtual ~GlslHighlighter(); void setDocument( QTextDocument *textdoc , const e_GlslLanguageType language); ............. > }
in *.cpp
GlslHighlighter::GlslHighlighter(QObject *parent) : QSyntaxHighlighter(parent) , m_language(GLSLT_Common) { }
That fixes your issue, you don't need to modify any calling code and the now added Q_Object macro will prevent future pain and misery
-
@J-Hilk said in cannot convert argument 1 from 'QWidget *' to 'QObject *':
QObject *parent
Thank You. It worked.
-
S SGaist has marked this topic as solved on