how connection variable in functin with spinBox
Good afternoon !
I am beginner in qt.I have a problem .How connection variable i in function with my spinBox.
This my function :
Code:
void DataPlot::insertCurve(Qt::Orientation o,
{
curve
->setPen
(QPen(Qt
::blue,
3));
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);
}
Re: how connection variable in functin with spinBox
You want the i variable to get the spin box value?Sorry, but i don't understand what you meant by connection.
Re: how connection variable in functin with spinBox
Code:
double y[sizeof(x) / sizeof(x[0])];
looking wroong. what is the reason for dividing size of array on size of array element?
Re: how connection variable in functin with spinBox
@GreenScape: It's the C style way of find out the size (number of elements) of an C-style array, but you are right it's completely useless (since the array size is known to be 10)
Re: how connection variable in functin with spinBox
no way man! sizeof(x) returns 10, but not 40! and sizeof(x) / sizeof(x[0]) == 2.5 ! maybe the old C-style way to find out the array size you mean? then sizeof(x) * sizeof(x[0]), because when array is local and not dynamucally allocated, sizeof() allways returns number of elements.
Re: how connection variable in functin with spinBox
@GreenScape: I have to contradict you: qDebug() << sizeof(x); //should print 40 in our case, and if you make 40/4 you get 10 (number of elements, the multiply wouldn't make sense)
I think (not 100% positive about this one)... it might fail if you use a pointer: like int *ptr = new int[10]; sizeof(ptr); returns 4(size of a pointer)
Anyway in this particular case it is not necessary because the number of elements it's known.
Re: how connection variable in functin with spinBox
Execuse me for me .I want that variable i changed with spinBox.help me,please )
Re: how connection variable in functin with spinBox
Is the function: void DataPlot::insertCurve(Qt::Orientation o, const QColor &c, double base) in the same object with QSpinBox?
If yes, just use:
Code:
double i = spinBoxObjectName.value();
If not tell us more "design" options, this function (void DataPlot::insertCurve(...)) you want to execute whenever the QSpinBox chage value, or just at some point (like user click a button, and the insertCurve executes with the current value of QSpinBox)
In this second case you will need signals and slots, but how to connect them depents on how/when you need the QSpinBox value, and in what object spinBox is... so we need a little more info.
And a little advice, you can use QVector (or std::vector) or QList instead of C-Style arrays, you have some facilities (like they know their size...)
Re: how connection variable in functin with spinBox
Thank you very much ,but I want that user can change in spinbox my function redraw !)) Execuse me for my English !)
Re: how connection variable in functin with spinBox
QSpinBox has a signal called valueChanged witch is emitted when the value changes.
You can connect that signal to the slot/slots that update what you need (if you connect with the functions you wrote make sure that you declare them with "public slots:" access specifier)
LE: depends on your design, but another idea is to have an int (or double) variable as a member in your class and write setter and getter functions for that (declare the setter function slot and connect the valueChanged signal to the setter slot <witch updates the member variable's value)
Re: how connection variable in functin with spinBox
how write this coonect! Execuse maybe we write examples !))
Re: how connection variable in functin with spinBox
Quote:
Originally Posted by
Sergey19
how write this coonect! Execuse maybe we write examples !))
One is allowed to read the documentation: QObject::connect().
EDIT: also SignalsandSlots (:p too late...)
Re: how connection variable in functin with spinBox
Documentation for signals and slots (you can find examples there)
Re: how connection variable in functin with spinBox
I read documentation....and write next code .but I have a mistale
View code:
Code:
void DataPlot::strob(Qt::Orientation o,
{
spinBox2->setRange(0,699);
// spinBox2->setValue(43);
spinBox2->show();
double i = spinBox2->value();
QObject::connect(spinBox2,
SIGNAL(valueChanged
(int)),i,
SLOT(value
));
curve
->setPen
(QPen(Qt
::blue,
3));
// 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);
}
Re: how connection variable in functin with spinBox
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.
Re: how connection variable in functin with spinBox
what mean ui !? I don't understand what function you mean.I understand that first is change spinbox and what about others !?
Re: how connection variable in functin with spinBox
How should
Code:
QObject::connect(spinBox2,
SIGNAL(valueChanged
(int)),i,
SLOT(value
));
work, if i is a double? the receiver in a connect statement has to be a QObject. (As it is written in the documentation!)
Re: how connection variable in functin with spinBox
I understand this ,but I don't know what receiver I must have in this connect )
Re: how connection variable in functin with spinBox
Any QObject derived class with a proper slot! And in your situation nothing will fit since your design is...
Re: how connection variable in functin with spinBox
Help me create slot .Thank you very much ))