Results 1 to 10 of 10

Thread: class header warnings.

  1. #1
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default class header warnings.

    I am confused obout declaring a class header.
    If I daclare a class
    class Products: public QWidget
    {
    Q_OBJECT
    public:
    Products( QWidget *parent = 0, const char *name = 0);
    and the constructor
    Products::Products( QWidget *parent, const char *name )
    {
    }
    I get the warnings
    products.cpp:40: warning: unused parameter ‘parent’
    products.cpp:40: warning: unused parameter ‘name’
    products.cpp:40: warning: unused parameter ‘parent’
    products.cpp:40: warning: unused parameter ‘name’
    I would appreciate some help. thanks

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: class header warnings.

    It should be

    Qt Code:
    1. Products::Products( QWidget *parent, const char *name ) : QWidget(parent,name)
    2. {
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: class header warnings.

    when I have
    Qt Code:
    1. Products::Products( QWidget *parent, const char *name ) : QWidget(parent,name)
    2. {
    3. }
    To copy to clipboard, switch view to plain text mode 
    as you suggest, I get
    products.cpp:42: error: no matching function for call to ‘QWidget::QWidget(QWidget*&, const char*&)’
    /usr/local/Trolltech/Qt-4.1.1/include/QtGui/qwidget.h:635: note: candidates are: QWidget::QWidget(const QWidget&)
    /usr/local/Trolltech/Qt-4.1.1/include/QtGui/qwidget.h:596: note: QWidget::QWidget(QWidgetPrivate&, QWidget*, Qt::WFlags)
    /usr/local/Trolltech/Qt-4.1.1/include/QtGui/qwidget.h:183: note: QWidget::QWidget(QWidget*, Qt::WFlags)
    In Qt3 I had what you suggested. I am using 4.1 in Ubuntu/Kubuntu 5.10.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: class header warnings.

    QWidget's ctor does not take a "const char*" parameter in Qt 4:
    QWidget::QWidget ( QWidget * parent = 0, Qt::WFlags f = 0 )
    J-P Nurmi

  5. #5
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: class header warnings.

    oh, then you can either use

    Qt Code:
    1. Products::Products( QWidget *parent, const char *name ) : QWidget(parent)
    2. {
    3. setObjectName(name);
    4. }
    To copy to clipboard, switch view to plain text mode 

    or, if you dont use the parameter "name"

    Qt Code:
    1. class Products: public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. Products( QWidget *parent = 0);
    To copy to clipboard, switch view to plain text mode 

    and the constructor

    Qt Code:
    1. Products::Products( QWidget *parent ) : QWidget(parent)
    2. {
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to munna for this useful post:

    impeteperry (30th May 2006)

  7. #6
    Join Date
    Jan 2006
    Location
    Gloucester, UK
    Posts
    18
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: class header warnings.

    While it is true that in this case you should really pass on the parent pointer and name pointer to the parent QWidget, that is not the reason for the warning message.

    If you declare variables but do not do use them, then the compiler will issue this warning.

  8. #7
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: class header warnings.

    Thanks munna. Now I have to go back to the books for why
    and guestgulkan, I am aware of that, but what I don't understand is why it worked in Qt3 and not in Qt4. I have never really understood what this whole class declaration is in Qt anyway.

    Thanks to you both.

  9. #8
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: class header warnings.

    Quote Originally Posted by impeteperry
    but what I don't understand is why it worked in Qt3 and not in Qt4
    because the constructor declaration in Qt3 is different from that of Qt4. You can find more about all this in the Qt Assistant.

    Quote Originally Posted by impeteperry
    have never really understood what this whole class declaration is in Qt anyway
    It is the way you do it in C++. I think you need to first learn more about C++.

  10. #9
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: class header warnings.

    I have not run across this in my c++ programming. This sample is taken from my program that designs multi-story precast concrete structures.
    Qt Code:
    1. class Sidesway
    2. {
    3. protected:
    4. float accumulated_area[20];
    5. float column_length[20];
    6. float length_factor[20];
    7. float left_el_length[20];
    To copy to clipboard, switch view to plain text mode 
    and the constructor
    Qt Code:
    1. #include "extern.h"
    2. #include "sidesway.h"
    3. #include "matrix.h"
    4. extern Sidesway SW, SW_O, SW_U;
    5. extern Matrix A, E, F, G, K, L, M, N, P, Q, R, S, V, W, Z;
    6.  
    7. Sidesway::Sidesway ()
    8. {
    9. unsigned n = 25 * 4 * 20;
    10. n += 11 * 3 * 4 * 20;
    11. n += 3 * 4 * 4 * 20;
    12. n += 2 * 3 * 4;
    13. n += 7 * 2 * 20;
    To copy to clipboard, switch view to plain text mode 
    Have I been missing somthing for the last 25 years?

  11. #10
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: class header warnings.

    What you do is fine. But there are better ways of doing.

    You can make your program more flexible and cleaner by using the other c++ techniques.

    It is all very simple. Any c++ tutorial website or c++ book will have everything that you need to undertand things in Qt.
    Last edited by munna; 31st May 2006 at 06:46. Reason: Typing Error

  12. The following user says thank you to munna for this useful post:

    impeteperry (31st May 2006)

Similar Threads

  1. Replies: 2
    Last Post: 4th May 2006, 19:17
  2. Qt in other class
    By Morea in forum Qt Programming
    Replies: 4
    Last Post: 9th April 2006, 17:08
  3. How to propagate from one class to another
    By mahe2310 in forum Qt Programming
    Replies: 15
    Last Post: 20th March 2006, 01:27
  4. Replies: 5
    Last Post: 15th March 2006, 07:33
  5. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

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
  •  
Qt is a trademark of The Qt Company.