PDA

View Full Version : Getting error on including custom widget class



rawfool
12th June 2013, 16:54
On including a custom class widget, I'm getting the following errors. How do I fix this ?


C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore\qdatet ime.h:123: error: C2589: '(' : illegal token on right side of '::'
C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore\qdatet ime.h:123: error: C2059: syntax error : '::'

My custom class looks like this -

//cbackbtnanime.h
#ifndef CBACKBTNANIME_H
#define CBACKBTNANIME_H

#include <QtGui>
#include <QWidget>
#include <QPushButton>
#include <QHBoxLayout>
#include <QStyleOption>

class CBackBtnAnime : public QWidget
{
Q_OBJECT
private:
QPushButton *backBtn;
QHBoxLayout *hLyt;
QPropertyAnimation * mAnimation;

public:
explicit CBackBtnAnime(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *pe)
{
Q_UNUSED(pe);
QStyleOption o;
o.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
}

bool eventFilter(QObject * object, QEvent * event)
{
if((parent() == object) & (event->type() == QEvent::MouseMove))
{
QMouseEvent * mouseEvent = static_cast<QMouseEvent *>(event);
if((mouseEvent->pos().x() < 50) && (mouseEvent->pos().y() < 30))
{
if(isHidden() && (mAnimation->state() != mAnimation->Running))
{
mAnimation->setStartValue(QRect(-2, 1, 0, 28));
mAnimation->setEndValue(QRect(0, 1, 50, 28));
disconnect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
mAnimation->start();
show();
}
}
else if(mAnimation->state() != mAnimation->Running)
{
if(!isHidden())
{
mAnimation->setEndValue(QRect(-2, 1, 0, 28));
mAnimation->setStartValue(QRect(0, 1, 50, 28));
connect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
mAnimation->start();
}
}
}

if((event->type() == QEvent::Leave) && (mAnimation->state() != mAnimation->Running))
{
qDebug("Inside QEvent::Leave");
if(!isHidden())
{
mAnimation->setEndValue(QRect(-2, 2, 0, 28));
mAnimation->setStartValue(QRect(0, 2, 50, 28));
connect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
mAnimation->start();
}
}

return QWidget::eventFilter(object, event);
}

signals:
void backBtnClicked();

public slots:

};
#endif // CBACKBTNANIME_H


//cbackbtmanime.cpp
#include "cbackbtnanime.h"

CBackBtnAnime::CBackBtnAnime(QWidget *parent) :
QWidget(parent)
{
this->setMouseTracking(true);
this->installEventFilter(this);
this->setStyleSheet("background-color: #454545;");
parent->installEventFilter(this);
mAnimation = new QPropertyAnimation(this, "geometry");
mAnimation->setDuration(250);

backBtn = new QPushButton(this);
backBtn->setFixedSize(50, 28);
backBtn->setIcon(QIcon(":/imgs/backToHome.png"));
backBtn->setIconSize(QSize(50, 28));
backBtn->setStyleSheet("QPushButton { background: transparent; border: 0px; border-radius: 20px; padding: 0px;}"
"QPushButton:hover {background: transparent; border: 1px solid #4cd3f5;}"
"QPushButton:pressed {background: transparent; border: 2px solid #4cd3f5;}"
"QToolTip {background: white; color: black; }");

connect(backBtn, SIGNAL(clicked()), this, SIGNAL(backBtnClicked()));

hLyt = new QHBoxLayout();
hLyt->setContentsMargins(0, 0, 0, 0);
this->setLayout(hLyt);
hLyt->addWidget(backBtn);

}

Kindly help me fix this issue. Thank you.

BalaQT
13th June 2013, 05:37
hi rawfool,

1.add #define NOMINMAX before including windows.h header.
2.Add compiler switch “/DNOMINMAX”

hope it helps

rawfool
13th June 2013, 06:28
1.add #define NOMINMAX before including windows.h header. I didn't include windows.h in any of my files.

2.Add compiler switch “/DNOMINMAX” Adding QMAKE_CXXFLAGS += /DNOMINMAX in my .pro file solved the problem. Thank you Bala.