我在线程类(继承QThread)里面用了一个QTimer,并有一个对应的slot函数。
运行的过程中会报错:
QObject:
Cannot create children for a parent that is in a different
thread.
(Parent is
myThread(0x98f6e10), parent's thread is QThread(0x98d08a0), current
thread is myThread(0x98f6e10)
QT中有QStringListModel,QDirModel,这都是先建立一个
model,然后listView.setmodel(model)或者treeVIew.setMODEL(MODEL);一般还有QStringlISTmodel是一个字符串一样的,所以可以,model.setStirngList(xx),xx是一个QStirngList系列,比如lsit<<'haha'<<'heheh'<<'oo';还可以设置这个视图view的一些属性,比如setedittriggers(
QAbstractItemView::
AnyKeyPressed|
QAbstractItemView::
DoubleClicked);这表示任何键只要双击就让他出于可编辑状态。
对于这个模型和视图,有个ModelIndex类比较重要,index是个索引,比如你要在一个model中插入一行,然后再view中显示,首先在view中得到你点击或者其他方式得到的索引行:int
row =
listview->currentIndex().row();然后再模型里插入一行,model-》insertRows(row,1);这插入的是在这个行的前面插入的。然后把这个插入的行,也就是这个row作为当前的的索引,QModelIndex
index = model-》index(row)
QModelIndex index =
model->index(row,
column, parent);
QModelIndex index =
model->index(row,
column, parent);
http://www.kuqin.com/upimg/allimg/071113/1824252.png
上图中,A项和C项作为model中顶层的兄弟项:
QModelIndex indexA =
model->index(0, 0,
QModelIndex());
QModelIndex indexC =
model->index(2, 1,
QModelIndex());
A有许多孩子,它的一个孩子B用以下代码获取:
QModelIndex indexB =
model->