QObject::connect: No such slot myclass::start_load_game(); in ../mc2d/myclass.cpp:40 QObject::connect: No such slot myclass::start_new_game(); in ../mc2d/myclass.cpp:41



  • Mam pewien problem. Nie wiem dlaczego nie wykrywa mi slotów z mojej klasy.
    plik myclass.cpp

    #include"game.h"
    #include"exgame.h"
    #include"myclass.h"
    #include<QGraphicsPixmapItem>
    #include<QMouseEvent>
    #include<QObject>
    #include <QKeyEvent>
    #include<QCoreApplication>
    
    void myclass::start_new_game()
    {
        new_game->setGeometry(QRect(QPoint(0,-100),QSize(180, 90)));
        newgame=0;
        started=1;
        qDebug()<<"New game";
        all = new game (newgame, "testsave");
        all->load_scene();
        view->setScene(all->return_scene());
    }
    
    void myclass::start_load_game()
    {
        load_game->setGeometry(QRect(QPoint(0,100),QSize(180, 90)));
        newgame=1;
        started=1;
        qDebug()<<"Load game";
        all = new game (newgame, "testsave");
        all->load_scene();
        view->setScene(all->return_scene());
    }
    
    myclass::myclass()
    {
        load_game = new QPushButton("Load game");
        new_game= new QPushButton("New game");
        load_game->setGeometry(QRect(QPoint(0,100),QSize(200, 100)));
        new_game->setGeometry(QRect(QPoint(0,-100),QSize(200, 100)));
        all->return_scene()->addWidget(load_game);
        all->return_scene()->addWidget(new_game);
        connect(load_game, SIGNAL (released()), this, SLOT (start_load_game();));
        connect(new_game, SIGNAL (released()), this, SLOT (start_new_game();));
    }
    
    

    plik myclass.h

    #include"game.h"
    #include<QPushButton>
    #include<QGraphicsPixmapItem>
    #include<QObject>
    #include <QKeyEvent>
    
    #ifndef MYCLASS_H
    #define MYCLASS_H
    
    class myclass: public QObject, public QGraphicsPixmapItem{
        Q_OBJECT
        QPushButton *new_game;
        QPushButton *load_game;
    public slots:
        void start_new_game ();
        void start_load_game ();
    public:
        myclass ();
    };
    #endif // MYCLASS_H
    


  • Hi, don't use semicolons in connect(), try change to

    connect(load_game, SIGNAL (released()), this, SLOT (start_load_game()));
    connect(new_game, SIGNAL (released()), this, SLOT (start_new_game()));
    

Log in to reply