Solved comboBox runtime enable/disable
-
Silly question: do you have any logic that re-enables that combo box ?
-
@SGaist
yes but work only with a pusbutton clicki think that i have to use the click event for enable / disable in real time
but combobox is added dinamically in runtime..
i've tried with:
connect(array_Fornitore[i], SIGNAL(clicked()), this, SLOT(ATTDIS(int i)));
Dialog .cpp
void ATTDIS(int i) { if (array_Origine[i].currentText == "ESTERNA") { array_Fornitore[i]->setDisabled(false); } if (array_Origine[i].currentText == "INTERNA") { array_Fornitore[i]->setDisabled(true); } } }
dialog .h
void ATTDIS(int i);
but don't work..
(array_Origine[i] use of undeclared identifier)
(array_Fornitore[i] use of undeclared identifier)
how can i pass array_Orgine[i] and array_Fornitore[i] to the function?? -
@TheCipo76
No offence intended, but from the same sort of thing in your previous posts you might like to read up on variable scope. And if you do understand that for normal variables, exactly the same applies when they are arrays.Rather than worrying about how to pass these arrays as parameters each time to slots and other individual functions, wouldn't your code logic be simpler if they were defined as member variables of your class (the dialog)?
-
@JonB
this is my dialog .h:class inserisciarticolo : public QDialog { Q_OBJECT public: explicit inserisciarticolo(QWidget *parent = nullptr); ~inserisciarticolo(); private slots: void on_pushButton_Annulla_clicked(); void on_pushButton_Inserisci_clicked(); //void ATTDIS(int i); private: Ui::inserisciarticolo *ui; QSqlDatabase aDatabase; QSqlQuery *aModel; //Array Componenti QLineEdit *array_Codice[10]; QLineEdit *array_Descrizione[10]; QSpinBox *array_Qta[10]; QComboBox *array_Origine[10]; //<-------------------- QComboBox *array_Fornitore[10]; //<------------------
-
@TheCipo76 said in comboBox runtime enable/disable:
connect(array_Fornitore[i], SIGNAL(clicked()), this, SLOT(ATTDIS(int i)));
You need to capture the var i in a lambda:
connect(array_Fornitore[i], &QComboBox::clicked, [i]() { ATTDIS(i); });
-
@mpergand
it's very interesting..i can capture i var and pass it to a slot function
if i have understand..but once i have done it what i have to do??
slot function do what i need? -
The lambda function becomes the slot function.
You probably need to capture 'this' as well to get access to methods and vars of the class instance. -
@mpergand
thank you very much for your reply
but i don't think i'm able to do this..now i try to learn about lamba expression
-
This post is deleted! -
i've tried with this code:
connect(array_Origine[i], SIGNAL(currentTextChanged(QString)) [i] () { ATTDIS(i);} );
and with this:
connect(array_Origine[i], SIGNAL(currentTextChanged(QString)) [this, i] () { ATTDIS(i);} );
but give me this error:
called object type 'char' is not a function or function pointer
how can i solve it??
void inserisciarticolo::ATTDIS(int i) { if (array_Origine[i]->currentText() == "ESTERNA") { array_Fornitore[i]->setDisabled(false); array_Fornitore[i]->repaint(); } if (array_Origine[i]->currentText() == "INTERNA") { array_Fornitore[i]->setDisabled(true); array_Fornitore[i]->repaint(); } }
-
@TheCipo76 said in comboBox runtime enable/disable:
connect(array_Origine[i], SIGNAL(currentTextChanged(QString)) [this, i] () { ATTDIS(i);} );
connect(array_Origine[i], &QComboBox::currentTextChanged) [this, i] (QString str) { ATTDIS(i);} );
-
@mpergand said in comboBox runtime enable/disable:
connect(array_Origine[i], &QComboBox::currentTextChanged) [this, i] (QString str) { ATTDIS(i);} );
don't work..
'QString' does not refer to a value
error: no matching member function for call to 'connect'
-
QComboBox box; box.setEditable(true); QObject::connect(&box,&QComboBox::currentTextChanged,[](QString str) { qDebug()<<str; }); box.show();
works as expected ....
-
sorry typo:
connect(array_Origine[i], &QComboBox::currentTextChanged ) <- remove )
[this, i] (QString str) { ATTDIS(i);} ); -
Finally works!
i passed no parameters to the function ATTDIS():
call the function then
i check with a loop all members of array (with "for" i index) and when
find "ESTERNA" enable comboFornitore[i]
when find "INTERNA" disable comboFornitore[i]Thanks to all for patience and help gived
-
@Cobra91151 Thank you. It worked.