declare pointers to controls in .ui file
-
The project has a dialog created as a class, and has files: quadratic.h, .cpp, and .ui. Is this sufficient to describe the situation?
Just in case, with an existing project did this:
File-> New File -> Qt -> Qt Designer Form Class
In the new dialog, ten QDoubleSpinBox controls were added.
What is the syntax to create a pointer to the controls in the class?
Here are some test pointer attempts, all solicited errors.
This is in quadratic.h
Items beginning with dspin_q are existing controls in quadratic.uiQDoubleSpinBox * test1 = dspin_q_input_a; QDoubleSpinBox * test2 = ui->dspin_q_input_a; QDoubleSpinBox * test3 = &dspin_q_input_a; QDoubleSpinBox * test4 = &ui->dspin_q_input_a;
Here is the basic concept of the final declaration, obviously incorrect.
static const int dspin_count = 10; QDoubleSpinBox * dsb_array[ dspin_count ] = { dspin_q_input_a, dspin_q_input_b, dspin_q_input_c, dspin_q_res_pos, dspin_q_res_neg, dspin_q_t1, dspin_q_t2, dspin_q_t3, dspin_q_t4, dspin_q_t5 };
Here is the basic concept of the goal for all this. This will go in quadratic.cpp
for( int count = 1, count < dspin_count, count ++ ) { dsb_array[ count ]->setMinimum( std::numeric_limits<double>::min() ); dsb_array[ count ]->setMaximum( std::numeric_limits<double>::max() ); dsb_array[ count ]->setButtonSymbols( QAbstractSpinBox::NoButtons ); // edit, just found this }
I asked ChatGPT for this but it persists in creating the control with a new object rather than referencing an existing control from the dot .ui file. How might that question be worded to ChatGPT?
-
Hi,
test2 is the correct variant.
Don't use a hardcoded array, use a QList so if you add or remove widgets, you only have to update the QList.
-
Hi,
test2 is the correct variant.
Don't use a hardcoded array, use a QList so if you add or remove widgets, you only have to update the QList.
@SGaist Item test2 produces an error, as do all the remainder.
Everything was commented out while trying to make progress in other areas.
Qlist? Looking into that.
-
@SGaist Item test2 produces an error, as do all the remainder.
Everything was commented out while trying to make progress in other areas.
Qlist? Looking into that.
@Bryan-Kelly
test2
is the only correct one. Did you read or click on the "fix available" (that means on the light bulb), or ignore it? It tells you thatQDoubleSpinBox
has not been declared, and you need to fix that by including the header file per the docs, not that the statement itself is inherently incorrect. -
@Bryan-Kelly
test2
is the only correct one. Did you read or click on the "fix available" (that means on the light bulb), or ignore it? It tells you thatQDoubleSpinBox
has not been declared, and you need to fix that by including the header file per the docs, not that the statement itself is inherently incorrect.@JonB I don't understand. If QDoubleSpinBox has not been declared, then how can I drop those controls onto the dialog?
Yes, I see the error message. Left and center click it and nothing happened. Right click to new a new long dialog.
Side question: How is that dialog dismissed?
Regarding that dialog, clicked a few selections and did not find an explanation. Which item needs to be selected?
Unexpected: Clicked on the light bulb of the image shown in my previous post, and the message disappeared. Now that line, the test2 line, compiles and the program runs. I cannot detect any difference in the code. I don't know why the error message closed out.
Edit: still working QList.
-
@JonB I don't understand. If QDoubleSpinBox has not been declared, then how can I drop those controls onto the dialog?
Yes, I see the error message. Left and center click it and nothing happened. Right click to new a new long dialog.
Side question: How is that dialog dismissed?
Regarding that dialog, clicked a few selections and did not find an explanation. Which item needs to be selected?
Unexpected: Clicked on the light bulb of the image shown in my previous post, and the message disappeared. Now that line, the test2 line, compiles and the program runs. I cannot detect any difference in the code. I don't know why the error message closed out.
Edit: still working QList.
@Bryan-Kelly Designer does not care about headers, it's a visual tool.
You want to use a class, you need to include its header where you use it. Check the includes at the top of your cpp file.