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. Making Slots in QT Designer with Visual Studio 2015

Making Slots in QT Designer with Visual Studio 2015

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 3.8k 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.
  • P Offline
    P Offline
    pistorinoj
    wrote on last edited by
    #1

    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.

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

      Hi
      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)
      QMetaObject::connectSlotsByName(MainWindow);
      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
      http://wiki.qt.io/New_Signal_Slot_Syntax

       connect( ui->radioButton, static_cast<void ( QRadioButton::* )(bool)>(&QRadioButton::clicked), this, &MainWindow::onClicked  );
      
      void MainWindow::onClicked(bool checked) {
        qDebug() << "im " << checked;
      }
      
      
      
      1 Reply Last reply
      0
      • P Offline
        P Offline
        pistorinoj
        wrote on last edited by
        #3

        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.

        mrjjM 1 Reply Last reply
        0
        • P pistorinoj

          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.

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

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

          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