MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(update()));
timer -> start(5000);
}
void MainWindow::update()
{
QStringList list;
list << __TIME__ ; //只调用了一次
QStringListModel *model = new QStringListModel(list,this);
ui -> listView -> setModel(model);
}
求教这个list如何才能重复再list中显示?
------最佳解决方案--------------------
哦。把model new 外面。 每次update的时候。往model里面插数据就好了。
setModel这些都在构造函数中做。
------其他解决方案--------------------
你要定时刷新List的显示? 可以自定义模型或直接使用QListWidget
------其他解决方案--------------------
自己顶下,求大神指点
------其他解决方案--------------------
额。。你这样。只能显示一个啊。而且每5秒。。就要new一个model...时间久了是不是内存就不够了。。。
------其他解决方案--------------------
想要啥效果呢
------其他解决方案--------------------
想实现每隔几秒list就刷新下时间,一行一行的打印出来
------其他解决方案--------------------
能不能给个简单的例子实现下功能呢?小弟新手=。=
------其他解决方案--------------------
小弟新手,对界面循环打印第一次做,能不能给些代码或者例子呢?
------其他解决方案--------------------
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),SLOT(update()));
timer->start(5000);
list<<__TIME__;
QStringListModel *model = new QStringListModel(list);
ui->listView -> setModel(model);
}
void MainWindow::update()
{
list.insert(0,"a");
}
只打印了list<<__TIME__;
update()中的东西没有显示,求高手指点下!!