Problem with SLOT



  • hi!

    i have a problem with a SLOT.
    in my header file:

    private slots:
        void getListiniArticolo(QString articolo);
    

    then, when i used the right mouse button:

    void Articoli::tblRight(const QPoint &pos) {
        int selRow = ui->tblArticoli->row(ui->tblArticoli->itemAt(pos));
        QString selArt = ui->tblArticoli->item(selRow, 1)->text();
    
        QMenu *menu = new QMenu(this);
        QAction* actionList = menu->addAction(QString("Listini articolo"));
        QAction* dtlArt = menu->addAction(QString("Dettaglio articolo"));
    
        connect(actionList, SIGNAL(triggered()), this, SLOT(getListiniArticolo(selArt)));
    
        menu->popup(ui->tblArticoli->viewport()->mapToGlobal(pos));
    }
    

    finally the implementation of the SLOT:

    void Articoli::getListiniArticolo(QString articolo) {
        ListiniArticolo *la = new ListiniArticolo(articolo);
        la->show();
    }
    

    but i have always this error:

    QObject::connect: No such slot Articoli::getListiniArticolo(QString(selArt))
    QObject::connect:  (receiver name: 'Articoli')
    

    where am I doing wrong??


  • Qt Champions 2016

    Hi
    In connect statements u may ONLY give type of parameters

    connect(actionList, SIGNAL(triggered()), this, SLOT(getListiniArticolo(selArt))); << selArt is a actual string. That you cannot do.

    You can say
    connect(actionList, SIGNAL(triggered()), this, SLOT(getListiniArticolo(QString))); << that is the type. this is ok.

    But since Triggered() do NOT have a string, you cannot connect to a Slot that expects one.

    so what you can do it

    connect(actionList, SIGNAL(triggered()), this, SLOT(getListiniArticolo()));
    

    void Articoli::getListiniArticolo() {
    int selRow = ui->tblArticoli->row(ui->tblArticoli->itemAt(pos));
    QString articolo= ui->tblArticoli->item(selRow, 1)->text();

    ListiniArticolo *la = new ListiniArticolo(articolo);
    la->show();
    

    }



  • @mrjj

    ok, i did this:

    private slots:
        void getListiniArticolo();
    
    private:
        QPoint point; // -> this is for function itemAt
    

    and then:

    void Articoli::tblRight(const QPoint &pos) {
        point = pos; // -> this is for function itemAt
        QMenu *menu = new QMenu(this);
        QAction* actionList = menu->addAction(QString("Listini articolo"));
        QAction* dtlArt = menu->addAction(QString("Dettaglio articolo"));
        menu->popup(ui->tblArticoli->viewport()->mapToGlobal(pos));
        connect(actionList, SIGNAL(triggered()), this, SLOT(getListiniArticolo()));
    }
    
    void Articoli::getListiniArticolo() {
        int selRow = ui->tblArticoli->row(ui->tblArticoli->itemAt(point));
        QString selArt = ui->tblArticoli->item(selRow, 1)->text();
        ListiniArticolo *la = new ListiniArticolo(selArt);
        la->show();
    }
    

    it seems to work properly!
    it might be fine for you?



  • How this part help me with Slot?
    void Articoli::tblRight(const QPoint &pos) {
    point = pos; // -> this is for function itemAt
    QMenu menu = new QMenu(this);
    QAction
    actionList = menu->addAction(QString("Listini articolo"));
    QAction* dtlArt = menu->addAction(QString("Dettaglio articolo"));
    menu->popup(ui->tblArticoli->viewport()->mapToGlobal(pos));
    connect(actionList, SIGNAL(triggered()), this, SLOT(getListiniArticolo()));
    }


  • Qt Champions 2016

    @fermatqt said in Problem with SLOT:

    QPoint point;

    That should work fine as long as not 2 different signals try to use it at same time.



  • @mrjj

    ok perfect!
    thank's a lot!


  • Qt Champions 2016

    @fermatqt
    Super.
    As a last note: ( just in case u didnt see)

    In a slot, you can get the widget that send the signal
    using the sender() function. Its is however always a QWidget QObject so you must try cast to the type
    to get full access.
    Like
    void mainwin::slot_for_trigger() {
    QAction* ac = qobject_cast<QAction* > ( sender() )
    if (ac) {
    do stuff with the Action...
      }
    }



  • @mrjj
    fantastic!!
    I did not know this!
    again thank you so much!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.