Writing code, however, is still required in order for the widgets to be fully functional in your application. Let's learn how to add items to our item view widgets using C++ code!
First, open up mainwindow.cpp and write the following code to the class constructor, right after ui->setupui(this):
ui->listWidget->addItem("My Test Item");
As simple as that, you have successfully added an item to the List Widget!
There is another way to add an item to the List Widget. But before that, we must add the following headers to mainwindow.h:
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QDebug> ...