Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with SLOT
Forum Updated to NodeBB v4.3 + New Features

Problem with SLOT

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fermatqt
    wrote on last edited by
    #1

    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??

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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();
      

      }

      F 1 Reply Last reply
      3
      • mrjjM mrjj

        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();
        

        }

        F Offline
        F Offline
        fermatqt
        wrote on last edited by
        #3

        @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?

        mrjjM 1 Reply Last reply
        1
        • T Offline
          T Offline
          Tusovshik
          wrote on last edited by
          #4

          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()));
          }

          1 Reply Last reply
          0
          • F fermatqt

            @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?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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.

            F 1 Reply Last reply
            2
            • mrjjM mrjj

              @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.

              F Offline
              F Offline
              fermatqt
              wrote on last edited by
              #6

              @mrjj

              ok perfect!
              thank's a lot!

              mrjjM 1 Reply Last reply
              0
              • F fermatqt

                @mrjj

                ok perfect!
                thank's a lot!

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @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...
                  }
                }

                F 1 Reply Last reply
                0
                • mrjjM mrjj

                  @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...
                    }
                  }

                  F Offline
                  F Offline
                  fermatqt
                  wrote on last edited by
                  #8

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

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved