PDA

View Full Version : [SOLVED] subclassing qlabel



mickey
28th April 2006, 14:39
Hi, I don't understand why this don't compile; any suggests?


#include <qlabel.h> //mylabel.h
class myLabel : public QLabel {
public:
myLabel(QWidget* parent=0, const char* name = 0);
//~myLabel():
};



//mylabel.cpp
#include "mylabel.h"
myLabel::myLabel(QWidget* parent, const char* name) :
QLabel( parent, name){
}

vratojr
28th April 2006, 15:44
The way you call the constructor doesn't match any QLabel's constructor.
http://doc.trolltech.com/4.1/qlabel.html

If you are creating classes with KDevelop 3.3 be carefull that it creates Qt classes in a way not suited fot Qt4.

jacek
28th April 2006, 15:50
Could you post the exact error message?

mickey
28th April 2006, 17:00
mylabel.cpp(3): error C2511: 'myLabel::myLabel(QWidget *,const char *)' : overloaded member function not found in 'myLabel'
mylabel.cpp(7): fatal error C1004: unexpected end of file found
mylabel.h(8): error C2226: syntax error : unexpected type 'QWidget'
mylabel.h(8): error C2238: unexpected token(s) preceding ';'
mylabel.h(8): error C3209: 'name' : Unicode identifiers are not yet supported
mylabel.h(8): error C3209: 'parent' : Unicode identifiers are not yet supported

jacek
28th April 2006, 17:08
mylabel.h(8): error C3209: 'name' : Unicode identifiers are not yet supported
mylabel.h(8): error C3209: 'parent' : Unicode identifiers are not yet supported
In what encoding did you save that file?

mickey
28th April 2006, 20:02
in the same way I saved the others, with .NET2003; what's happen?

jacek
28th April 2006, 20:08
in the same way I saved the others, with .NET2003; what's happen?
Does this file look normal when you open it in notepad?

mickey
28th April 2006, 20:30
yes, they appear like text files; I tried to delete the file and create new files; but don't change.....After I've subclassed QPopupmenu and it don't get any problems....

mickey
29th April 2006, 11:42
I haven't change nothing and the errors changed so:


mylabel.cpp(2): error C2062: type 'char' unexpected
mylabel.cpp(2): error C2065: 'parent' : undeclared identifier
mylabel.cpp(2): error C2065: 'QWidget' : undeclared identifier
mylabel.cpp(2): error C2653: 'myLabel' : is not a class or namespace name
mylabel.cpp(3): error C2065: 'name' : undeclared identifier
mylabel.cpp(3): error C2448: 'QLabel' : function-style initializer appears to be a function definition
mylabel.cpp(3): error C3861: 'parent': identifier not found, even with argument-dependent lookup
If I take out costructor class in .ccp (taking <include>) it compile and link!
Should the compiler get me an error without costructor???

mickey
29th April 2006, 17:43
I don't understand what was happen; but I founded in .h 'cosnt' instead const!!
Before I cuted and pasted but I see that in the first post const is true; this below works and it seems thae same of the first post;


#include "mylabel.h"

myLabel::myLabel (QWidget* parent, const char* name) :
QLabel (parent,name) {

}

#include <qlabel.h>
class myLabel : public QLabel {
public:
myLabel(QWidget* parent=0, const char* name=0);
~myLabel(){};
};
:confused:

lyuts
4th June 2008, 14:43
When you do the following

myLabel::myLabel (QWidget* parent, const char* name)
:QLabel (parent,name) {

you take the parameters from specified in your myLabel constructor and try to call the original QLabel's constructor with those parameters. But in fact none of QLabel's constructors accept both QWidget and const char*. You are trying to call this constructor


QLabel(QWidget *parent, const char *name)

but it has


QLabel ( QWidget * parent = 0, Qt::WindowFlags f = 0 )
and
QLabel ( const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0 )