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. SIGNAL(triggered()) is not respond
Forum Updated to NodeBB v4.3 + New Features

SIGNAL(triggered()) is not respond

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 4.4k Views 1 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.
  • H Offline
    H Offline
    House15
    wrote on last edited by
    #1

    Good day every one. Another situation from me.

    Where is a conditions of the problem:

    @
    private:
    //...
    QMenu *cm;
    QAction sendFileAction;
    //...

    Dialog::Dialog(QWidget parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    //...
    cm=new QMenu(this);
    sendFileAction=new QAction(tr("&Send file"), this);
    //...
    connect(sendFileAction,SIGNAL(triggered()),this,SLOT(on_context_menu_triggered(QAction
    )));
    //...
    }

    void Dialog::on_context_menu_triggered(QAction *pAction)
    {
    QString strContextAction = pAction->text().remove("&");
    if(strContextAction=="Send file")
    {QMessageBox::about(this,"Informtation","'Send file' in context menu was triggered");}
    }
    @

    And choosing "Send file" in context menu gives nothing. I read about problems with triggered() signal. Are there any analogues?

    There was also an attempt to connect via:
    connect(cm,SIGNAL(triggered(QAction*)),this,SLOT(on_context_menu_triggered(QAction*)));

    but results are same. Any ideas?

    Many thanks in advance.

    [EDIT: code formatting, please wrap in @-tags, Volker]

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KA51O
      wrote on last edited by
      #2

      connect(..) returns a boolean, you might want to check the returned value of connect to see if the connection is established.

      also the parameters in your SIGNAL don't match the parameter expected by your SLOT.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        House15
        wrote on last edited by
        #3

        Thanks a lot! Now it's work! =)

        I will don't set SOLVED this by for now, just in case.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KA51O
          wrote on last edited by
          #4

          Glad I could help. BTW if you need the sender of the received signal in your slot you can always do this:

          @
          QObject* sender = QObject::sender();
          // and then cast it to a class (if its known to you)
          if(qobject_cast<QObjectSubclass*>(sender) != NULL)
          {
          qobject_cast<QObjectSubclass*>(sender)->getOrSetWhatYouWant();
          }
          @

          In your case like this:
          @
          void Dialog::on_context_menu_triggered()
          {
          QObject* sender = QObject::sender();
          if(qobject_cast<QAction*>(sender) != NULL)
          {
          QString strContextAction = qobject_cast<QAction*>(sender)->text().remove("&");
          if(strContextAction=="Send file")
          {
          QMessageBox::about(this,"Informtation","'Send file' in context menu was triggered");
          }
          }
          }
          @

          1 Reply Last reply
          0
          • H Offline
            H Offline
            House15
            wrote on last edited by
            #5

            You just saving me! Thanks you =)

            1 Reply Last reply
            0

            • Login

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