Results 1 to 11 of 11

Thread: [SOLVED] subclassing qlabel

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default [SOLVED] subclassing qlabel

    Hi, I don't understand why this don't compile; any suggests?
    Qt Code:
    1. #include <qlabel.h> //mylabel.h
    2. class myLabel : public QLabel {
    3. public:
    4. myLabel(QWidget* parent=0, const char* name = 0);
    5. //~myLabel():
    6. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //mylabel.cpp
    2. #include "mylabel.h"
    3. myLabel::myLabel(QWidget* parent, const char* name) :
    4. QLabel( parent, name){
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by mickey; 28th April 2006 at 14:42.
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    La Spezia,Italy
    Posts
    77
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclassing qlabel

    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.
    Last edited by vratojr; 28th April 2006 at 15:46.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclassing qlabel

    Could you post the exact error message?

  4. #4
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: subclassing qlabel

    Qt Code:
    1. mylabel.cpp(3): error C2511: 'myLabel::myLabel(QWidget *,const char *)' : overloaded member function not found in 'myLabel'
    2. mylabel.cpp(7): fatal error C1004: unexpected end of file found
    3. mylabel.h(8): error C2226: syntax error : unexpected type 'QWidget'
    4. mylabel.h(8): error C2238: unexpected token(s) preceding ';'
    5. mylabel.h(8): error C3209: 'name' : Unicode identifiers are not yet supported
    6. mylabel.h(8): error C3209: 'parent' : Unicode identifiers are not yet supported
    To copy to clipboard, switch view to plain text mode 
    Regards

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclassing qlabel

    Quote Originally Posted by mickey
    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?

  6. #6
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: subclassing qlabel

    in the same way I saved the others, with .NET2003; what's happen?
    Regards

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: subclassing qlabel

    Quote Originally Posted by mickey
    in the same way I saved the others, with .NET2003; what's happen?
    Does this file look normal when you open it in notepad?

  8. #8
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: subclassing qlabel

    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....
    Regards

  9. #9
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: subclassing qlabel

    I haven't change nothing and the errors changed so:
    Qt Code:
    1. mylabel.cpp(2): error C2062: type 'char' unexpected
    2. mylabel.cpp(2): error C2065: 'parent' : undeclared identifier
    3. mylabel.cpp(2): error C2065: 'QWidget' : undeclared identifier
    4. mylabel.cpp(2): error C2653: 'myLabel' : is not a class or namespace name
    5. mylabel.cpp(3): error C2065: 'name' : undeclared identifier
    6. mylabel.cpp(3): error C2448: 'QLabel' : function-style initializer appears to be a function definition
    7. mylabel.cpp(3): error C3861: 'parent': identifier not found, even with argument-dependent lookup
    To copy to clipboard, switch view to plain text mode 
    If I take out costructor class in .ccp (taking <include>) it compile and link!
    Should the compiler get me an error without costructor???
    Regards

  10. #10
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default [SOLVED] Re: subclassing qlabel

    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;
    Qt Code:
    1. #include "mylabel.h"
    2.  
    3. myLabel::myLabel (QWidget* parent, const char* name) :
    4. QLabel (parent,name) {
    5.  
    6. }
    7.  
    8. #include <qlabel.h>
    9. class myLabel : public QLabel {
    10. public:
    11. myLabel(QWidget* parent=0, const char* name=0);
    12. ~myLabel(){};
    13. };
    To copy to clipboard, switch view to plain text mode 
    Regards

  11. #11
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [SOLVED] subclassing qlabel

    When you do the following
    Qt Code:
    1. myLabel::myLabel (QWidget* parent, const char* name)
    2. :QLabel (parent,name) {
    To copy to clipboard, switch view to plain text mode 

    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

    Qt Code:
    1. QLabel(QWidget *parent, const char *name)
    To copy to clipboard, switch view to plain text mode 

    but it has

    Qt Code:
    1. QLabel ( QWidget * parent = 0, Qt::WindowFlags f = 0 )
    2. and
    3. QLabel ( const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0 )
    To copy to clipboard, switch view to plain text mode 
    I'm a rebel in the S.D.G.

Similar Threads

  1. Trouble with QLabel
    By dany_MB in forum Newbie
    Replies: 3
    Last Post: 14th August 2009, 08:21
  2. Replies: 3
    Last Post: 17th July 2008, 07:43
  3. QLabel ScaledContents ignored by style sheet?
    By WinchellChung in forum Newbie
    Replies: 3
    Last Post: 27th February 2008, 14:50
  4. QLabel size policy
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2007, 17:57
  5. QT4 layout of complex dialog is very slow
    By cboles in forum Qt Programming
    Replies: 15
    Last Post: 28th April 2006, 19:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.