Results 1 to 3 of 3

Thread: Getting error on including custom widget class

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Getting error on including custom widget class

    On including a custom class widget, I'm getting the following errors. How do I fix this ?
    Qt Code:
    1. C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore\qdatetime.h:123: error: C2589: '(' : illegal token on right side of '::'
    2. C:\Qt\Qt5.0.2\5.0.2\msvc2010\include\QtCore\qdatetime.h:123: error: C2059: syntax error : '::'
    To copy to clipboard, switch view to plain text mode 
    My custom class looks like this -
    Qt Code:
    1. //cbackbtnanime.h
    2. #ifndef CBACKBTNANIME_H
    3. #define CBACKBTNANIME_H
    4.  
    5. #include <QtGui>
    6. #include <QWidget>
    7. #include <QPushButton>
    8. #include <QHBoxLayout>
    9. #include <QStyleOption>
    10.  
    11. class CBackBtnAnime : public QWidget
    12. {
    13. Q_OBJECT
    14. private:
    15. QPushButton *backBtn;
    16. QHBoxLayout *hLyt;
    17. QPropertyAnimation * mAnimation;
    18.  
    19. public:
    20. explicit CBackBtnAnime(QWidget *parent = 0);
    21. protected:
    22. void paintEvent(QPaintEvent *pe)
    23. {
    24. Q_UNUSED(pe);
    25. o.initFrom(this);
    26. QPainter p(this);
    27. style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
    28. }
    29.  
    30. bool eventFilter(QObject * object, QEvent * event)
    31. {
    32. if((parent() == object) & (event->type() == QEvent::MouseMove))
    33. {
    34. QMouseEvent * mouseEvent = static_cast<QMouseEvent *>(event);
    35. if((mouseEvent->pos().x() < 50) && (mouseEvent->pos().y() < 30))
    36. {
    37. if(isHidden() && (mAnimation->state() != mAnimation->Running))
    38. {
    39. mAnimation->setStartValue(QRect(-2, 1, 0, 28));
    40. mAnimation->setEndValue(QRect(0, 1, 50, 28));
    41. disconnect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
    42. mAnimation->start();
    43. show();
    44. }
    45. }
    46. else if(mAnimation->state() != mAnimation->Running)
    47. {
    48. if(!isHidden())
    49. {
    50. mAnimation->setEndValue(QRect(-2, 1, 0, 28));
    51. mAnimation->setStartValue(QRect(0, 1, 50, 28));
    52. connect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
    53. mAnimation->start();
    54. }
    55. }
    56. }
    57.  
    58. if((event->type() == QEvent::Leave) && (mAnimation->state() != mAnimation->Running))
    59. {
    60. qDebug("Inside QEvent::Leave");
    61. if(!isHidden())
    62. {
    63. mAnimation->setEndValue(QRect(-2, 2, 0, 28));
    64. mAnimation->setStartValue(QRect(0, 2, 50, 28));
    65. connect(mAnimation, SIGNAL(finished()), this, SLOT(hide()));
    66. mAnimation->start();
    67. }
    68. }
    69.  
    70. return QWidget::eventFilter(object, event);
    71. }
    72.  
    73. signals:
    74. void backBtnClicked();
    75.  
    76. public slots:
    77.  
    78. };
    79. #endif // CBACKBTNANIME_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //cbackbtmanime.cpp
    2. #include "cbackbtnanime.h"
    3.  
    4. CBackBtnAnime::CBackBtnAnime(QWidget *parent) :
    5. QWidget(parent)
    6. {
    7. this->setMouseTracking(true);
    8. this->installEventFilter(this);
    9. this->setStyleSheet("background-color: #454545;");
    10. parent->installEventFilter(this);
    11. mAnimation = new QPropertyAnimation(this, "geometry");
    12. mAnimation->setDuration(250);
    13.  
    14. backBtn = new QPushButton(this);
    15. backBtn->setFixedSize(50, 28);
    16. backBtn->setIcon(QIcon(":/imgs/backToHome.png"));
    17. backBtn->setIconSize(QSize(50, 28));
    18. backBtn->setStyleSheet("QPushButton { background: transparent; border: 0px; border-radius: 20px; padding: 0px;}"
    19. "QPushButton:hover {background: transparent; border: 1px solid #4cd3f5;}"
    20. "QPushButton:pressed {background: transparent; border: 2px solid #4cd3f5;}"
    21. "QToolTip {background: white; color: black; }");
    22.  
    23. connect(backBtn, SIGNAL(clicked()), this, SIGNAL(backBtnClicked()));
    24.  
    25. hLyt = new QHBoxLayout();
    26. hLyt->setContentsMargins(0, 0, 0, 0);
    27. this->setLayout(hLyt);
    28. hLyt->addWidget(backBtn);
    29.  
    30. }
    To copy to clipboard, switch view to plain text mode 

    Kindly help me fix this issue. Thank you.

  2. #2
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Getting error on including custom widget class

    hi rawfool,

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

    hope it helps

  3. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    254
    Thanks
    92
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Getting error on including custom widget class

    Quote Originally Posted by BalaQT View Post
    1.add #define NOMINMAX before including windows.h header.
    I didn't include windows.h in any of my files.
    Quote Originally Posted by BalaQT View Post
    2.Add compiler switch “/DNOMINMAX”
    Adding QMAKE_CXXFLAGS += /DNOMINMAX in my .pro file solved the problem. Thank you Bala.

Similar Threads

  1. Replies: 7
    Last Post: 18th August 2011, 14:43
  2. Replies: 18
    Last Post: 11th March 2011, 13:21
  3. Qt Creator Custom widget plugin being replaced with parent class
    By mhill in forum Qt Tools
    Replies: 0
    Last Post: 28th July 2010, 18:58
  4. Replies: 1
    Last Post: 6th May 2010, 11:05
  5. Error when promoting a custom widget
    By engin in forum Qt Tools
    Replies: 1
    Last Post: 15th December 2006, 16:00

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.