QlistWidget 用に 2 つのプッシュボタン (InsertItem および RemoveLast アイテム) を作成しました。これは、3 つのアイテム (Chair、Table、Mirror) のリストを表示するために使用する必要があります。これらのアイテムを順番に挿入し、削除するコードを書くのに助けが必要です。
私のコード:
----mainwindow.h---
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class QListWidget;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void insertItem();
void removeItem();
private:
Ui::MainWindow *ui;
};
#endif
---mainwindow.cpp---
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->pushButton,SIGNAL(clicked()), this,SLOT(insertItem()));
connect(ui->pushButton_2,SIGNAL(clicked()), this,SLOT(removeItem()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::insertItem()
{
}
void MainWindow::removeItem()
{
}