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. Do you need to disconnect buttons?
Qt 6.11 is out! See what's new in the release blog

Do you need to disconnect buttons?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.9k Views 2 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.
  • A Offline
    A Offline
    aftershocker1
    wrote on last edited by
    #1

    Hello

    I am making an application that steps thought a series of processes. Once complete step one, the user presses the "next" button and it moves to a new looking page. To do this I have once page set up and when the user presses "next" the labels, text images are changed with code to give the page a new look.

    To do this at the start of each new page function there is a new connect to two buttons, one of the buttons is to carry out the test one the page(normally data extraction from USB) and the other button is the "next" button.

    at top of void onclick_btn_next7()

    //connect button
    connect(ui.btn_next, &QPushButton::clicked, this, &ManuNonEng::onclick_btn_next8);
    connect(ui.btn_doSomething, &QPushButton::clicked, this, &ManuNonEng::onclick_getTempData);
    

    at top of void onclick_btn_next8()

    //connect button
    connect(ui.btn_next, &QPushButton::clicked, this, &ManuNonEng::onclick_btn_next9);
    connect(ui.btn_doSomething, &QPushButton::clicked, this, &ManuNonEng::onclick_getAccTempData);
    

    at top of void onclick_btn_next9()

    //connect button
    connect(ui.btn_next, &QPushButton::clicked, this, &ManuNonEng::onclick_btn_next10);
    connect(ui.btn_doSomething, &QPushButton::clicked, this, &ManuNonEng::onclick_getAdcTempData);
    
    

    The problem I am have is the previous pages are still trying to open when further through the steps and the application becomes very slow. I have put qDebug()'s in to for checking and the further through the steps the early pages are trying to open more and more and the button is pressed.

    Like I said I think it is because the same button is connected so I was wondering if the button is then connected to running multiple functions when it is clicked.

    Any advice would be excellent!

    Thanks

    1 Reply Last reply
    0
    • A Offline
      A Offline
      aftershocker1
      wrote on last edited by
      #2

      To further explain what is happening. When I open page 8 it runs the "open page 8" function 2 times.
      When I open page 9 it runs the "open page 8" a further 7 times in the background.
      When i open page 10 it runs the "open page 8" a further 21 times times in the background.
      When i open page 11 it runs the "open page 8" a further 67 times times in the background.

      1 Reply Last reply
      0
      • JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        I don't follow exactly what you are saying, but you should not be executing connect()s to connect the same signal and slot objects together more than once. If you do so, Qt will maintain multiple duplicate connections and call the slot many times on the signal.

        Usually you arrange to only do connect()s once, preferably when the slot object is created. If that is not convenient, are you aware that connect() accepts a Qt::UniqueConnection parameter, to ignore duplicate connections?

        You can also forcibly call QObject::disconnect() to explicitly remove signal/slot pairs. Usually this is not necessary, as Qt does disconnects for you if you delete signal or slot objects.

        1 Reply Last reply
        2
        • A Offline
          A Offline
          aftershocker1
          wrote on last edited by
          #4

          Yeah, that is accatly what was happening. I was looking to do some sort of disconnect() that worked in the same that that connect() and was just told by someone that I could just do myButton.disconnect(); Working well now :-)

          Simple problems have simple solutions!

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            Aren't you re-inventing QWizard ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1

            • Login

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