PDA

View Full Version : class header warnings.



impeteperry
30th May 2006, 05:19
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

munna
30th May 2006, 06:06
It should be




Products::Products( QWidget *parent, const char *name ) : QWidget(parent,name)
{

}

impeteperry
30th May 2006, 07:01
when I have
Products::Products( QWidget *parent, const char *name ) : QWidget(parent,name)
{
}
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.

jpn
30th May 2006, 07:11
QWidget's ctor does not take a "const char*" parameter in Qt 4:
QWidget::QWidget ( QWidget * parent = 0, Qt::WFlags f = 0 ) (http://doc.trolltech.com/4.1/qwidget.html#QWidget)

munna
30th May 2006, 07:14
oh, then you can either use




Products::Products( QWidget *parent, const char *name ) : QWidget(parent)
{
setObjectName(name);
}



or, if you dont use the parameter "name"




class Products: public QWidget
{
Q_OBJECT
public:
Products( QWidget *parent = 0);



and the constructor




Products::Products( QWidget *parent ) : QWidget(parent)
{

}

guestgulkan
30th May 2006, 07:39
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.

impeteperry
30th May 2006, 14:02
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.

munna
30th May 2006, 14:21
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.


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

impeteperry
31st May 2006, 02:31
I have not run across this in my c++ programming. This sample is taken from my program that designs multi-story precast concrete structures.
class Sidesway
{
protected:
float accumulated_area[20];
float column_length[20];
float length_factor[20];
float left_el_length[20];and the constructor
#include "extern.h"
#include "sidesway.h"
#include "matrix.h"
extern Sidesway SW, SW_O, SW_U;
extern Matrix A, E, F, G, K, L, M, N, P, Q, R, S, V, W, Z;

Sidesway::Sidesway ()
{
unsigned n = 25 * 4 * 20;
n += 11 * 3 * 4 * 20;
n += 3 * 4 * 4 * 20;
n += 2 * 3 * 4;
n += 7 * 2 * 20;
Have I been missing somthing for the last 25 years?

munna
31st May 2006, 06:30
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.