Do you need to disconnect buttons?
-
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
-
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. -
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 thatconnect()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. -
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!