Results 1 to 2 of 2

Thread: Custom widget problem

  1. #1
    Join Date
    Jan 2006
    Location
    Skopje, Macedonia
    Posts
    11
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Unhappy Custom widget problem

    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
    Qt Code:
    1. #ifndef PTEMPLATE_H
    2. #define PTEMPLATE_H
    3.  
    4. #include <QWidget>
    5. #include <QColor>
    6. #include <QVariant>
    7.  
    8.  
    9.  
    10.  
    11.  
    12. class PTemplate: public QWidget
    13. {
    14. Q_OBJECT
    15.  
    16.  
    17. Q_PROPERTY (bool EqualLeads READ EqualLeads WRITE setEqualLeads)
    18. Q_PROPERTY (int FirstLeadLength READ FirstLeadLength WRITE setFirstLeadLength)
    19.  
    20. public:
    21.  
    22.  
    23. PTemplate(QWidget *parent=0);
    24.  
    25. bool EqualLeads() const {return curEqualLeads;}
    26. void setEqualLeads(bool newValue);
    27.  
    28. int FirstLeadLength() const {return curFirstLeadLength;};
    29. void setFirstLeadLength(int newLeadLength);
    30.  
    31. QSize sizeHint();
    32. QSize minimumSizeHint();
    33.  
    34.  
    35. private:
    36. QVariant curValue;
    37. bool curEqualLeads;
    38. int curFirstLeadLength;
    39.  
    40. }
    41.  
    42. #endif
    To copy to clipboard, switch view to plain text mode 

    .cpp
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "templateqt4.h"
    4.  
    5.  
    6. PTemplate::PTemplate(QWidget *parent)
    7. : QWidget(parent)
    8. {
    9. setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    10.  
    11. setEqualLeads(true);
    12. setFirstLeadLength(10);
    13.  
    14. resize(minimumSizeHint());
    15.  
    16. }
    17.  
    18. QSize PTemplate::sizeHint()
    19. {
    20. return minimumSizeHint();
    21. }
    22.  
    23. QSize PTemplate::minimumSizeHint()
    24. {
    25. return QSize(10,40);
    26. }
    27.  
    28. /***************************************************/
    29. /* PROPERTY HANDLERS */
    30. /***************************************************/
    31.  
    32. void PTemplate::setEqualLeads(bool newValue)
    33. {
    34. if (curEqualLeads != newValue)
    35. {
    36. curEqualLeads = newValue;
    37. update();
    38. }
    39. }
    40.  
    41. void PTemplate::setFirstLeadLength(int newLeadLength)
    42. {
    43. if (curFirstLeadLength != newLeadLength)
    44. {
    45. curFirstLeadLength = newLeadLength;
    46. update();
    47. }
    48. }
    49.  
    50. /* END PROPERTY HANDLERS */
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2.  
    3. #include "templateqt4.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. PTemplate *temp = new PTemplate;
    9. temp->show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    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
    Qt Code:
    1. #include <QApplication>
    2.  
    3. //#include "templateqt4.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. // PTemplate *temp = new PTemplate;
    9. // temp->show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    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

    GREETZ, chombium
    Last edited by jacek; 27th September 2006 at 16:40. Reason: changed [ code ] to [ quote ] to allow wrapping

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom widget problem

    Add a semicolon after PTemplate definition (in the header file).

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

  3. The following user says thank you to jacek for this useful post:

    chombium (27th September 2006)

Similar Threads

  1. Replies: 3
    Last Post: 12th April 2006, 08:20
  2. Problem reimplementing QSpinBox in a custom widget
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2006, 08:12
  3. Replies: 4
    Last Post: 24th March 2006, 22:50
  4. Problem with custom widget
    By jnana in forum Qt Programming
    Replies: 3
    Last Post: 15th March 2006, 11:55
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.