⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Making Slots in QT Designer with Visual Studio 2015

  • I am new to QT so I apologize in advance if this is a stupid question.
    I am using QT 5.10.11 with VS2015 in C++ on a Win10 platform.

    I have some radio buttons that I want to handle the signals from.
    I understand that QT Designer does not have the "go to slots" option of QT Creator.
    I do not know how to connect a slot to the radio button clicked signal.

    I saw this StackOverFlow question: https://stackoverflow.com/questions/12227993/qt-designer-missing-go-to-slot-in-context-menu

    I tried that approach calling my slot on_radioButton_click() and on_radioButton_clicked() and neither appear to work. Based on what was said there, I did not write my own connect call.

    How do I write my own slot and connect it to a radioButton signals?

    Thanks for any help.

  • Lifetime Qt Champion

    Did you install the Visual Studio plugin for Qt ?
    I was under the expression it allowed stuff like slots and UI editing.
    ( while i do use the visual studio compiler, i do not use visual studio editor so not sure
    what UI / slot features it actually offers)

    Anyway, the naming trick
    on_radioButton_click only works if there is a UI file involved as calls (in the setupUI function)
    which checks names for widgets and slot and tries to auto connect them.

    However, nothing stops you to just connecting manually ?

    // note this is using the new syntax and not SIGNAL and SLOT macros

     connect( ui->radioButton, static_cast<void ( QRadioButton::* )(bool)>(&QRadioButton::clicked), this, &MainWindow::onClicked  );
    void MainWindow::onClicked(bool checked) {
      qDebug() << "im " << checked;

  • I did install the QT Visual Studio add-ins, that is where QT Designer is coming from.

    So, I do have a UI file. For whatever reason, the trick of auto connect is not working.

    However, adding a manual connect like you said works perfectly.

    Thanks very much.

  • Lifetime Qt Champion

    Ok, you can run it manually if you want to.
    in any case explicit
    connections is recommended as auto connect feature is very fragile to renaming of slot or widgets so
    its bound to break on larger app with multiple programmers.

Log in to reply