Hi, can you help me, please...
i have..
Qt Code:
To copy to clipboard, switch view to plain text mode
x - is 5x or 15x, ... but when i click on button, how i can know which button was pressed ?..
some example will help me..
Hi, can you help me, please...
i have..
Qt Code:
To copy to clipboard, switch view to plain text mode
x - is 5x or 15x, ... but when i click on button, how i can know which button was pressed ?..
some example will help me..
QSignalMapper:
Qt Code:
for (...) { connect(button, SIGNAL(clicked()), signalMapper, SLOT(map())); signalMapper->setMapping(...); } connect(signalMapper, SIGNAL(mapped(argtype)), this, SIGNAL(clicked(argtype)));To copy to clipboard, switch view to plain text mode
argtype can be int, QString, anything supported by QSignalMapper
thank you for quick reply ;-)
Use Sender()
eg: Button *clickedButton = qobject_cast<Button *>(sender());
Qt Code:
void Calculator::unaryOperatorClicked() { Button *clickedButton = qobject_cast<Button *>(sender()); double operand = display->text().toDouble(); double result = 0.0; if (clickedOperator == tr("Sqrt")) { if (operand < 0.0) { abortOperation(); return; } result = sqrt(operand); } else if (clickedOperator == tr("x\262")) { result = pow(operand, 2.0); } else if (clickedOperator == tr("1/x")) { if (operand == 0.0) { abortOperation(); return; } result = 1.0 / operand; } waitingForOperand = true; }To copy to clipboard, switch view to plain text mode
Rajesh Kumar Singh
Bangalore, India.
Qt Search
Must Watch:
See how we can connect digital world objects to our day to day life….
sender() violates the object-oriented principle of modularity, which is why you should not use it unless there's no alternative (and in this case, there is).
In your example, you could remove 'clickedButton' from your code completely, and have 'clickedOperator' passed to it as a parameter, which is much more readable.
Hi a have a new problem...
when i want change properties of created button, program go to run-time error.
Qt Code:
void create () ( Struct.b[Struct.top++]=b; )To copy to clipboard, switch view to plain text mode
theStruct is declare in class MainWindow in public. And in othe fun.:
Qt Code:
Struct.b[..]->setText("change");To copy to clipboard, switch view to plain text mode
Hi, look at the calc example bundled with Qt in examples. Looks like your case.
Cheers,
-- tanuki
thanks again but i dont get it just yet...
all the widgets have to know about the myData Object in MainWindow. so is it better to solve this by Singleton or do i give all the widgets a reference to my Data in the constructor, Or is there another way how it should be done?
in that way all the widgets have the pointer to the data in themselve and i i update it in another widget the changes are accessableQt Code:
{ Q_OBJECT public: public slots: void showMesssage(); private: QMessageBox *message; }; //and in MainWIndow i make: myData * data; myMessage *mess(this,data);To copy to clipboard, switch view to plain text mode
I hope you get my question
thank
Post does not make any sense in this thread
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
Bookmarks