Subclassing QGraphicsView
Here is my iadfuqgraphicsview.h. I encounter errors such as
iadfuqgraphicsview.h:13: error: expected unqualified-id at end of input
iadfuqgraphicsview.h:13: error: expected `,' or `;' at end of input
How can I solve this?
Code:
#ifndef IADFUQGraphicsView_H
#define IADFUQGraphicsView_H
#include <QtGui>
#include <QObject>
{
Q_OBJECT
public:
~IADFUQGraphicsView(){} ;
protected:
private:
}
#endif
Also, How can I create an iadfuqgraphicsview.cpp that properly overrides the contextMenuEvent and mousePressEvent methods of QGraphicsView? Can anybody create a code for that?
Re: Subclassing QGraphicsView
Quote:
Originally Posted by
sincnarf
I encounter errors such as
iadfuqgraphicsview.h:13: error: expected unqualified-id at end of input
iadfuqgraphicsview.h:13: error: expected `,' or `;' at end of input
You're missing a semi-colon (";") at the end of the class declaration:
Code:
class Blaa
{
}; // <---
Quote:
Also, How can I create an iadfuqgraphicsview.cpp that properly overrides the contextMenuEvent and mousePressEvent methods of QGraphicsView? Can anybody create a code for that?
Take a look at the Elastic Nodes Example. GraphWidget inherits QGraphicsView and reimplements a few event handlers. You can do it the same way.
Re: Subclassing QGraphicsView
Thanks but my problem is I need to use the constructor of the QGraphicsView that accepts QWidget as a parameter... how can I do that? also where is the proper place to place that constructor? in .cpp or .h ?
Re: Subclassing QGraphicsView
The proper way is to declare it in the header and define(implement) it in the cpp.
Code:
//in the header
{
public:
~CustomView();
};
//in the cpp
{
//...
}
Regards
Re: Subclassing QGraphicsView
I have compilation problems using your recommended consctructor
This is my iadfuqgraphicsview.cpp file
Code:
#include "iadfuqgraphicsview.h"
{
}
and this is my iadfuqgrahicsview.h file
Code:
#ifndef IADFUQGRAPHICSVIEW_H
#define IADFUQGRAPHICSVIEW_H
#include <QtGui>
{
Q_OBJECT
public:
~IADFUQGraphicsView();
};
my errors are as follows:
error: prototype for `IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsS cene*, QWidget*)' does not match any in class `IADFUQGraphicsView'
error: candidates are: IADFUQGraphicsView::IADFUQGraphicsView(const IADFUQGraphicsView&)
Re: Subclassing QGraphicsView
o m g. Can't figure this out. Sorry for my simple mistakes in C. I'm more inclined to 'other' programming languages than C and C++.
Re: Subclassing QGraphicsView
Well, first of all, don't include QtGui in the header. Do it in the cpp.
Include only QGraphicsView and keep the forward declarations.
And are those all your sources? Could you post the complete ones?
Re: Subclassing QGraphicsView
Using your previous tips I got compilation errors that says
iadfuqgraphicsview.h:14: error: expected `,' or `...' before '*=' token
iadfuqgraphicsview.cpp:4: error: prototype for `IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsS cene*, QWidget*)' does not match any in class `IADFUQGraphicsView'
iadfuqgraphicsview.h:10: error: candidates are: IADFUQGraphicsView::IADFUQGraphicsView(const IADFUQGraphicsView&)
iadfuqgraphicsview.h:14: error: IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsSc ene*, QWidget)
iadfuqgraphicsview.cpp
Code:
#include <QtGui>
#include "iadfuqgraphicsview.h"
{
}
complete header code
Code:
#ifndef IADFUQGRAPHICSVIEW_H
#define IADFUQGRAPHICSVIEW_H
{
Q_OBJECT
public:
~IADFUQGraphicsView();
};
#endif
Re: Subclassing QGraphicsView
But I told you to include QGraphicsView in the header.
Re: Subclassing QGraphicsView
same error. sorry kind of sleepy here.
I tried to place
#include <QtGui/QGraphicsView>
also tried to place
#include <QGraphicsView>
also tried the forward declaration
class QGraphicsView;
still got the same error as before
iadfuqgraphicsview.h:16: error: expected `,' or `...' before '*=' token
iadfuqgraphicsview.cpp:4: error: prototype for `IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsS cene*, QWidget*)' does not match any in class `IADFUQGraphicsView'
iadfuqgraphicsview.h:12: error: candidates are: IADFUQGraphicsView::IADFUQGraphicsView(const IADFUQGraphicsView&)
iadfuqgraphicsview.h:16: error: IADFUQGraphicsView::IADFUQGraphicsView(QGraphicsSc ene*, QWidget)
Re: Subclassing QGraphicsView
Try this:
the header(customgv.h):
Code:
#ifndef CUSTOMGV_H
#define CUSTOMGV_H
#include <QGraphicsView>
{
Q_OBJECT
public:
~customgv();
};
#endif
the cpp(customgv.cpp):
Code:
#include <QtGui>
#include "customgv.h"
{
}
You might have another class named IADF...
Regards
Re: Subclassing QGraphicsView
What the.. this worked. Now trying to override contextMenuEvent and mousePressEvent s