PDA

View Full Version : Custom widget problem



chombium
27th September 2006, 16:32
Hi,

I tried porting one of my widgets from qt3 to qt4 (rewriting it from the scratch) and I end up in some problems in compiling.
I just don't know what's te problem. I even compared my widget with the
Qt's example analogclock, everything seems the same....

Here is the code and the make output

.h


#ifndef PTEMPLATE_H
#define PTEMPLATE_H

#include <QWidget>
#include <QColor>
#include <QVariant>





class PTemplate: public QWidget
{
Q_OBJECT


Q_PROPERTY (bool EqualLeads READ EqualLeads WRITE setEqualLeads)
Q_PROPERTY (int FirstLeadLength READ FirstLeadLength WRITE setFirstLeadLength)

public:


PTemplate(QWidget *parent=0);

bool EqualLeads() const {return curEqualLeads;}
void setEqualLeads(bool newValue);

int FirstLeadLength() const {return curFirstLeadLength;};
void setFirstLeadLength(int newLeadLength);

QSize sizeHint();
QSize minimumSizeHint();


private:
QVariant curValue;
bool curEqualLeads;
int curFirstLeadLength;

}

#endif


.cpp


#include <QtGui>

#include "templateqt4.h"


PTemplate::PTemplate(QWidget *parent)
: QWidget(parent)
{
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);

setEqualLeads(true);
setFirstLeadLength(10);

resize(minimumSizeHint());

}

QSize PTemplate::sizeHint()
{
return minimumSizeHint();
}

QSize PTemplate::minimumSizeHint()
{
return QSize(10,40);
}

/************************************************** */
/* PROPERTY HANDLERS */
/************************************************** */

void PTemplate::setEqualLeads(bool newValue)
{
if (curEqualLeads != newValue)
{
curEqualLeads = newValue;
update();
}
}

void PTemplate::setFirstLeadLength(int newLeadLength)
{
if (curFirstLeadLength != newLeadLength)
{
curFirstLeadLength = newLeadLength;
update();
}
}

/* END PROPERTY HANDLERS */


main.cpp


#include <QApplication>

#include "templateqt4.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
PTemplate *temp = new PTemplate;
temp->show();
return app.exec();
}


make output


g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o main.o main.cpp
main.cpp:5: error: new types may not be defined in a return type
main.cpp:5: note: (perhaps a semicolon is missing after the definition of ‘PTemplate’)
main.cpp:5: error: two or more data types in declaration of ‘main’
main.cpp:5: error: ‘::main’ must return ‘int’
make: *** [main.o] Error 1


Than I tried to comment the lines from
the main.cpp that create the widget, so
that I can see the errors from the widget

main.cpp


#include <QApplication>

//#include "templateqt4.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// PTemplate *temp = new PTemplate;
// temp->show();
return app.exec();
}


make output


g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o main.o main.cpp
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o templateqt4.o templateqt4.cpp
templateqt4.cpp:6: error: new types may not be defined in a return type
templateqt4.cpp:6: note: (perhaps a semicolon is missing after the definition of ‘PTemplate’)
templateqt4.cpp:6: error: return type specification for constructor invalid
make: *** [templateqt4.o] Error 1


I use qt 4.1.2 with gcc 4.0
Any Ideas are welcomed. Probably is some stupid
mestake, that I just can't see it :confused:

GREETZ, chombium

jacek
27th September 2006, 16:41
Add a semicolon after PTemplate definition (in the header file).


templateqt4.cpp:6: note: (perhaps a semicolon is missing after the definition of ‘PTemplate’)