Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9182961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:41:12+00:00 2026-06-17T18:41:12+00:00

I’m trying to make three mutually exclusive radio buttons with three QToolButtons (basically; they’re

  • 0

I’m trying to make three mutually exclusive radio buttons with three QToolButtons (basically; they’re subclassed). I set Checkable to true in the designer and now have two problems:

  1. They need to be mutually exclusive, i.e. clicking one button should uncheck all the others.
  2. There is always exactly one button checked.

The first one was easy to solve with the following slot code that was connected to toggled(bool):

void Foo::slot_radio1(bool on) {
    if (on) {
        tb_radio2->setChecked(false);
        tb_radio3->setChecked(false);
    }
}

and likewise for the other two buttons as well. Not nice, but works. The second is a little trickier and that’s where my question comes into play.

In most GUI toolkits you can cancel an event in an event handler if necessary which could be used here to cancel the toggle if the currently-active button would be toggled off. However, that applies to systems that use event handlers and pass around event objects that can be modified. With signals/slots, as far as I understood, you’re handling events after the fact and have no influence on them. Apart from the problem that you don’t have access to the event data anyway. The naïve but stupid approach I tried was

if (!on) {
    tb_radio1->setChecked(true);
}

basically re-checking the button whenever it’s unchecked – which results in a stack overflow as it recursively triggers every other slot again, and again, …

Is there generally a nice and clean approach to achieving this? I’d rather not disconnect slots, change state and connect them again. I’m probably missing something obvious or trivial for anyone who worked with Qt for years, but I guess that’s not me and thus it eludes me.


It got a little messy now, but works, based on the blockSignals suggestion by Tim and Andreas:

void WinPhoenix::slot_radio1(bool on) {
    if (on) {
        bool before2 = radio2->blockSignals(true);
        bool before3 = radio3->blockSignals(true);
        radio2->setChecked(false);
        radio3->setChecked(false);
        radio2->blockSignals(before2);
        radio3->blockSignals(before3);
    } else {
        bool before = radio1->blockSignals(true);
        radio1->setChecked(true);
        radio1->blockSignals(before);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:41:13+00:00Added an answer on June 17, 2026 at 6:41 pm

    I’d rather not disconnect slots, change state and connect them again.

    You could use QObject::blockSignals() to temporarily disable signals sent by an object:

    bool before = tb_radio1->blockSignals(true);
    tb_radio1->setChecked(true);
    tb_radio1->blockSignals(before);
    

    Other than that, you could consider using a QActionGroup() to implement the mutual exclusiveness.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.