关闭

QTreeView 小问题

标签: signalheaderobjecttree文档
1738人阅读 评论(0) 收藏 举报
分类:

使用如下代码:

connect(ui->treeView,SIGNAL(doubleClicked(const QModelIndex & index)),model,SLOT(itemSelected(const QModelIndex & index)));

按照文档应该没有问题,可是报错如下

Object::connect: No such signal QTreeView::doubleClicked(const QModelIndex & index) in...

后来到网上找到一篇文章,
http://qt4-x11.sourcearchive.com/documentation/4.1.2/classQTreeWidget_bff7ec30b95f987290aca04f4817ce07.html


QTreeWidget::QTreeWidget ( QWidget *  parent = 0  )  [explicit]

Constructs a tree widget with the given parent.

Definition at line 1798 of file qtreewidget.cpp.

References QAbstractItemView::activated()QAbstractItemView::clicked()QTreeView::collapsed()QObject::connect()QAbstractItemView::currentChanged(),QTreeView::dataChanged()QAbstractItemView::doubleClicked()QAbstractItemView::entered()QTreeView::expanded()QTreeView::header(),itemSelectionChanged()QAbstractItemView::model()QAbstractItemView::pressed()QAbstractItemView::selectionChanged(),QAbstractItemView::selectionModel()QHeaderView::setClickable(), and QTreeView::setModel().

    : QTreeView(*new QTreeWidgetPrivate(), parent)
{
    QTreeView::setModel(new QTreeModel(0, this));
    // view signals
    connect(this, SIGNAL(pressed(QModelIndex)), SLOT(emitItemPressed(QModelIndex)));
    connect(this, SIGNAL(clicked(QModelIndex)), SLOT(emitItemClicked(QModelIndex)));
    connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(emitItemDoubleClicked(QModelIndex)));
    connect(this, SIGNAL(activated(QModelIndex)), SLOT(emitItemActivated(QModelIndex)));
    connect(this, SIGNAL(entered(QModelIndex)), SLOT(emitItemEntered(QModelIndex)));
    connect(this, SIGNAL(expanded(QModelIndex)), SLOT(emitItemExpanded(QModelIndex)));
    connect(this, SIGNAL(collapsed(QModelIndex)), SLOT(emitItemCollapsed(QModelIndex)));
    // selection signals
    connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
            this, SLOT(emitCurrentItemChanged(QModelIndex,QModelIndex)));
    connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
            this, SIGNAL(itemSelectionChanged()));
    // model signals
    connect(model(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
            this, SLOT(emitItemChanged(QModelIndex)));

    header()->setClickable(false);
}


改成

connect(ui->treeView,SIGNAL(doubleClicked(QModelIndex)),model,SLOT(ReadItem()));


void ReadItem(const QModelIndex & index = QModelIndex());
就OK了。
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:139363次
    • 积分:1689
    • 等级:
    • 排名:千里之外
    • 原创:10篇
    • 转载:89篇
    • 译文:0篇
    • 评论:9条
    最新评论
    友情链接