Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QGraphicsSceneMousePressEvent inconsistent dll linkage



  • my MainWindow header file looks like this;
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    #include <QMainWindow>
    #include <QGraphicsItem>
    #include <QGraphicsScene>
    #include <QGraphicsSceneMouseEvent>
    #include "QtGui"
    #include "QMouseEvent"
    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    private slots:
    void on_actionOpen_triggered();

    void on_pushButtonZoomOut_clicked();
    
    void on_pushButtonZoomIn_clicked();
    
    void on_pushButtonNewLine_clicked();
    
    void on_pushButtonLastLine_clicked();
    

    // void taskCompleted();
    void on_pushButtonRotate_clicked();

    void on_pushButtonRotateA_clicked();
    

    private:
    Ui::MainWindow *ui;
    QGraphicsItem *item;
    QGraphicsScene *scene;
    QGraphicsEllipseItem *ellipse;
    };

    #endif // MAINWINDOW_H
    ..............
    /Now mainwindow.cpp file like this:-/
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QtCore>
    #include <QtGui>
    #include "QFileDialog"
    #include <QDebug>

    QString im;
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_actionOpen_triggered() //Open Button, to open File Dailog
    {
    QFileDialog dialog(this);
    dialog.setNameFilter(tr("Images(*.png *.xpm *.jpg *.JPG .JPEG"));
    dialog.setViewMode(QFileDialog::Detail);
    QString filName = QFileDialog::getOpenFileName(this,tr("Open Images"), "./", tr("Image Files(
    .jpg *.png *.JPEG *.JPG"));
    if(!filName.isEmpty()){
    QImage image(filName);
    item = new QGraphicsPixmapItem(QPixmap::fromImage(image));
    scene = new QGraphicsScene(this);
    ui->graphicsView->setScene(scene);
    scene->addItem(item);
    im = "open";
    }

    }

    void MainWindow::on_pushButtonZoomOut_clicked()
    {
    ui->graphicsView->scale(.5,.5);
    }

    void MainWindow::on_pushButtonZoomIn_clicked()
    {
    ui->graphicsView->scale(2,2);
    }

    void MainWindow::on_pushButtonNewLine_clicked()
    {
    if(im =="open"){
    QBrush redBrush(Qt::red);
    QBrush blueBrush(Qt::blue);
    QPen blackpen(Qt::black);
    blackpen.setWidth(6);
    ellipse = scene->addEllipse(10,10,100,100,blackpen,redBrush);
    ellipse->setFlag(QGraphicsItem::ItemIsMovable);
    }
    }

    void MainWindow::on_pushButtonLastLine_clicked()
    {

    }
    void QGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event){
    int x = event->scenePos().x();
    qDebug()<<x;
    }
    void MainWindow::on_pushButtonRotate_clicked()
    {
    ui->graphicsView->rotate(-10);
    }

    void MainWindow::on_pushButtonRotateA_clicked()
    {
    ui->graphicsView->rotate(+10);
    }
    ..........................................................
    Now i am getting error E:\test\untitled\customview.cpp:19: warning: C4273: 'QGraphicsScene::mousePressEvent' : inconsistent dll linkage

    If i am using in header file
    void QGraphicsSceneMouseEvent(QGraphicsSceneMouseEvent *ev);
    then I try it in cpp file as
    MainWindow::QGraphicsSceneMouseEvent(QGraphicsSceneMouseEvent *ev){
    qDebug()<<ev->scenePos().x();
    }
    Then it shows nothing..
    I want to know distance on two points from image. Those two point i will show on image.For that I need to know mouse position only on Image(which is displayed on graphics)
    Thanks for help. Please help me out


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    void QGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
    

    belongs to QGraphicsScene, you can't reimplement it like that. You have to do it in a subclass of QGraphicsScene.

    For the second question, you have another thread already there


Log in to reply