how write this coonect! Execuse maybe we write examples !))
how write this coonect! Execuse maybe we write examples !))
One is allowed to read the documentation: QObject::connect().
EDIT: also SignalsandSlots (too late...)
Last edited by Lykurg; 5th August 2010 at 12:19. Reason: updated contents
Documentation for signals and slots (you can find examples there)
I read documentation....and write next code .but I have a mistale
View code:Qt Code:
void DataPlot::strob(Qt::Orientation o, { spinBox2->setRange(0,699); // spinBox2->setValue(43); spinBox2->show(); double i = spinBox2->value(); // double i ; double x[10]; double y[sizeof(x) / sizeof(x[0])]; for ( uint k = 0; k < sizeof(x) / sizeof(x[0]); k++ ) { double v = i+k * 1.5; if ( o == Qt::Horizontal ) { x[k] = v; y[k] = base; } else { x[k] = base; y[k] = v; } } curve->setData(x, y, sizeof(x) / sizeof(x[0])); curve->attach(this); }To copy to clipboard, switch view to plain text mode
Obviously you don't have read the documentation carefully! First you really should use layouts, and further, i is no object its a integer which you cant use in a connect statement as a receiver!
If you want to redraw your function when the value of i changes make three functions: the first sets up the ui (only one time), next is a slot you call when your spinbox changes, and a third is your paint function depending on your local variable i. You also can combine the 2nd and 3rd function by skiping the local variable and using spinBox2->value() directly in the slot. But rally first set up your gui and don't do it all in one function because that won't work.
what mean ui !? I don't understand what function you mean.I understand that first is change spinbox and what about others !?
Last edited by Sergey19; 5th August 2010 at 13:16.
How shouldwork, if i is a double? the receiver in a connect statement has to be a QObject. (As it is written in the documentation!)Qt Code:
To copy to clipboard, switch view to plain text mode
I understand this ,but I don't know what receiver I must have in this connect )
Any QObject derived class with a proper slot! And in your situation nothing will fit since your design is...
Help me create slot .Thank you very much ))
As others have mentioned, you need to spend some time doing your homework:
http://doc.trolltech.com/4.6/signalsandslots.html
Read through this documentation and you should easily be able to accomplish what you want to do... As of now, your design/code reflects a fairly fundamental misunderstanding of how Qt works.
It will be very difficult to help you otherwise.
Isn't it better to put the 'i' variable in the class definition? (not a local variable to that function)
And declare a function (a slot, with "public slots:" access specifier) and that function will look like:
and connect this slot with the SpinBox valueChanged signal:Qt Code:
void YourClass::set_i(double input) { i = input;} //i is your member variable iTo copy to clipboard, switch view to plain text mode
(in your class constructor if the spinbox2 is member of the same class!)
Qt Code:
connect(spinBox2,SIGNAL(valueChanged(double)), this, SLOT(set_i(double));To copy to clipboard, switch view to plain text mode
Note: You can do it with double or int, but the QSpinBox doesn't have a valueChanged(double) only int
QDoubleSpinBox has valueChanged(double) not int
And we can't create a complete design, we can only give you advices, because we don't know the actual problem (don't even know the design of your class)
Bookmarks