Results 1 to 4 of 4

Thread: C++ forbids declarations with no type

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Post C++ forbids declarations with no type

    I'm new to Qt and trying to learn the Graphics and Animation frameworks. I created a simple app that using code pulled from the AnimatedTiles example app,but I cannot get it to compile.

    The apps consist of main.cpp, posterimg.cpp and posterimg.h.

    PosterImg is the same as the Pixmap class in the AnimatedTiles sample. I'm simply renamed it and moved it out of the main class. Unfortunately, now the app won't compile. Compiling produces the following errors:

    posterimg.cpp:4: error: ISO C++ forbids declaration of 'PosterImage' with no type
    posterimg.cpp:4: error: no 'int PosterImg::PosterImage(QPixmap&)' member function declared in class 'PosterImg'


    Can anybody show me what I'm doing wrong?

    Code for PosterImg.h

    Qt Code:
    1. #ifndef POSTERIMG_H
    2. #define POSTERIMG_H
    3.  
    4. #include <QPixmap>
    5. #include <QGraphicsPixmapItem>
    6.  
    7. class PosterImg : public QObject, public QGraphicsPixmapItem
    8. {
    9. Q_OBJECT
    10. Q_PROPERTY(QPointF pos READ WRITE setPos)
    11.  
    12. public:
    13. PosterImg(QPixmap &pix);
    14.  
    15.  
    16. };
    17.  
    18. #endif // POSTERIMG_H
    To copy to clipboard, switch view to plain text mode 

    Code for PosterImg.cpp

    Qt Code:
    1. #include "posterimg.h"
    2.  
    3.  
    4. PosterImg::PosterImage(QPixmap &pix)
    5. {
    6. setCacheMode(DeviceCoordinateCache);
    7. }
    To copy to clipboard, switch view to plain text mode 

    Code for main.cpp
    Qt Code:
    1. #include <QtCore>
    2. #include <QtGui>
    3.  
    4.  
    5. #include "posterimg.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. Q_INIT_RESOURCE(uc1res);
    10. QApplication app(argc, argv);
    11.  
    12. textItem->setHtml("<font color=\"black\"><b>Hello</b>");
    13. textItem->setPos(100,50);
    14.  
    15. QPixmap myPix(":/images/kinetic.png");
    16. PosterImg *myImg = new PosterImg(myPix);
    17.  
    18. scene.addItem(img);
    19. scene.addItem(textItem);
    20. scene.setBackgroundBrush(Qt::white);
    21.  
    22. view.setRenderHints(QPainter::Antialiasing);
    23. view.setTransformationAnchor(QGraphicsView::NoAnchor);
    24. view.setScene(&scene);
    25. view.show();
    26. view.setFocus();
    27.  
    28.  
    29. return app.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 

    Brian

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: C++ forbids declarations with no type

    Well, error tells you all you need, and the error has nothing to with Qt, it is pure C++. Note that C++ in case sensitive.
    Qt Code:
    1. #include "posterimg.h"
    To copy to clipboard, switch view to plain text mode 
    is not
    Qt Code:
    1. #include "PosterImg.h"
    To copy to clipboard, switch view to plain text mode 
    and that you probably need. Also make sure that the path is right.

    EDIT: and
    Qt Code:
    1. PosterImg::PosterImage
    To copy to clipboard, switch view to plain text mode 
    should be
    Qt Code:
    1. PosterImg::PosterImg
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 5th August 2010 at 21:48. Reason: updated contents

  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: C++ forbids declarations with no type

    Typo: PosterImg::PosterImage(QPixmap &pix) correct should be PosterImg::PosterImg(...)

  4. #4
    Join Date
    Aug 2010
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: C++ forbids declarations with no type

    Thanks for the help. All that trouble caused by one typo.

    Brian

Similar Threads

  1. Replies: 13
    Last Post: 31st July 2010, 15:19
  2. Replies: 12
    Last Post: 29th April 2010, 13:22
  3. Replies: 2
    Last Post: 14th October 2008, 09:05
  4. forbids declaration of QHash with no type
    By nina1983 in forum Qt Programming
    Replies: 4
    Last Post: 16th July 2008, 13:05
  5. Forward declarations needed for some?
    By doktorn in forum Newbie
    Replies: 6
    Last Post: 28th November 2007, 08:56

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.