#include "widget.h" #include "ui_widget.h" #include <QtGui/QCompleter> #include <QStringList> Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); QStringList strings; strings << "Biao" << "Biao Huang" << "Mac" << "MacBook" << "MacBook Pro" << "Mac Pro"; completer = new QCompleter(strings, this); ui->comboBox->clear(); ui->comboBox->addItems(strings); ui->comboBox->setEditable(true); ui->comboBox->setCompleter(completer); } Widget::~Widget() { delete ui; delete completer; }