Qt WidgetTable. Generating multiple data in just a push of a button

213 views Asked by At

This is my first time using qt creator and a newbie to C++ language. I'm creating a GUI that will generate data (in numbers) into a widgetTable. My initial value of x serves as the starting point and the terminal value is my end point. the increment will be added to the initial value of x until it reaches the terminal value. How do I add the result VALUES into my widget table`enter

enter image description here

As you can see in my GUI there are two widget tables, the one on the left is composed of 2 columns.

Example:
Initial value of x is -5
Terminal value of x is 5
Increment is 1

Output on the column of values of x when Generate is clicked, Values of x

-5
-4
-3
-2
-1
0
1
2
3
4
5

I need help. I need to know what qt code is needed

1

There are 1 answers

0
dazewell On

There's a lot of information abailable on the internet and official documentation with a lot of examples, you may take a look at this: https://wiki.qt.io/How_to_Use_QTableWidget and this: http://doc.qt.io/qt-5.4/model-view-programming.html

Basically, Qt uses model/view architecture, that means the data is placed somewhere NOT "in" widget. This "somewhere" is called a model (it has a lot of other functions by the way). It's mission is to hold the data. On the other hand is a view, that doesn't know anything about your data and asks the model to describe it. This approach gives a lot of advantages and is prefferable if you are planning to manipulate with data.

QTableWidget simplifies this approach hiding the model and giving you some functions like:

setItem(int row, int column, QTableWidgetItem * item)
item(int row, int column) const

and etc. (the whole list is here).

Well, this is how adding a simple text to the first row and a second column will look like:

_tableWidget->setItem(0, 1, new QTableWidgetItem("Hello"));

In your situation you'll need a slot with for cycle, that will generate such an objects, and connect it with your "Generate" button's signal clicked().

connect(_generateButton, SIGNAL(clicked()), this, SLOT(evalTable()));

Good luck.