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. connect QAction a signal to QAction b slot AND connect QAction b signal to QAction a slot
Forum Updated to NodeBB v4.3 + New Features

connect QAction a signal to QAction b slot AND connect QAction b signal to QAction a slot

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 158 Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hello,
    I want to set up 3 actions (a, b and c) in a toolbar they all connect to the same slot in the mainwindow (Hello()), and when b is toggled then c is disabled and the other way: when c is toggled then b is disabled.
    Something like that:

    m_toolBar = addToolBar(tr("selection"));
    
    QAction *aAct = new QAction(tr("&a"), this);
    aAct->setCheckable(true);
    connect(aAct, &QAction::triggered, this, &MainWindow::Hello);
    m_toolBar->addAction(aAct);
    
    QAction *bAct = new QAction(tr("&b"), this);
    bAct->setCheckable(true);
    connect(bAct, &QAction::triggered, this, &MainWindow::Hello);
    connect(bAct, &QAction::toggled, cAct, &QAction::setDisabled);
    m_toolBar->addAction(bAct);
    
    QAction *cAct = new QAction(tr("&c"), this);
    cAct->setCheckable(true);
    connect(cAct, &QAction::triggered, this, &MainWindow::Hello);
    connect(cAct, &QAction::toggled, bAct, &QAction::setDisabled);
    m_toolBar->addAction(cAct);
    

    But when I do that, i have a crash. Someone can help me?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      problem solved: action c was not initialized ...
      I should have write that instead:

      m_toolBar = addToolBar(tr("selection"));
      
      QAction *aAct = new QAction(tr("&a"), this);
      aAct->setCheckable(true);
      connect(aAct, &QAction::triggered, this, &MainWindow::Hello);
      m_toolBar->addAction(aAct);
      
      QAction *bAct = new QAction(tr("&b"), this);
      bAct->setCheckable(true);
      connect(bAct, &QAction::triggered, this, &MainWindow::Hello);
      //connect(bAct, &QAction::toggled, cAct, &QAction::setDisabled);
      m_toolBar->addAction(bAct);
      
      QAction *cAct = new QAction(tr("&c"), this);
      cAct->setCheckable(true);
      connect(cAct, &QAction::triggered, this, &MainWindow::Hello);
      connect(cAct, &QAction::toggled, bAct, &QAction::setDisabled);
      connect(bAct, &QAction::toggled, cAct, &QAction::setDisabled); //<---
      m_toolBar->addAction(cAct);
      
      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