Results 1 to 3 of 3

Thread: for declaration of struct QToolButton

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default for declaration of struct QToolButton

    why do I receive error when I do not #include for example QToolButton , but rather go for its forward class declaration?

    Qt Code:
    1. #ifndef PLAYVIDEO_H
    2. #define PLAYVIDEO_H
    3.  
    4. #include <QWidget>
    5.  
    6.  
    7.  
    8.  
    9. class PlayVideo : public QWidget
    10. {
    11. Q_OBJECT
    12. public:
    13. PlayVideo(QWidget *parent = 0);
    14.  
    15. private:
    16. void createButtons();
    17. void createControls();
    18.  
    19.  
    20. QToolButton *playButton;
    21. QToolButton *pauseButton;
    22. QToolButton *stopButton;
    23.  
    24. QGridLayout *controlsLayout;
    25. QHBoxLayout *buttonsLayout;
    26. QVBoxLayout *mainLayout;
    27.  
    28. };
    29.  
    30. #endif // PLAYVIDEO_H
    To copy to clipboard, switch view to plain text mode 

    error: forward declaration of ‘struct QToolButton’

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: for declaration of struct QToolButton

    I don't think that code will give that error.

    (I've just tried it, and it doesn't give that error...)
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: for declaration of struct QToolButton

    You need to include the header where you actually use the variable.
    The header you posted is valid.
    The error probably comes in the implementation where you call a method on your tool button variable.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Forward Declaration of struct QCloseEvent ????
    By drake1983 in forum Newbie
    Replies: 2
    Last Post: 3rd February 2009, 15:16
  2. error: forward declaration of 'struct QPushButton'
    By prykHetQuo in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2009, 23:20
  3. static declaration
    By jhearon in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2008, 21:37
  4. QtXml: xml declaration
    By Gopala Krishna in forum Newbie
    Replies: 1
    Last Post: 2nd June 2007, 12:12
  5. Declaration problems
    By scarvenger in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2007, 02:05

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.