首页| 论坛| 消息

标题:QTableView可以接受到鼠标双击信号,但是不能执行我的槽函数,请高手指点
作者:stevenltx
日期:2016-08-24 14:35
内容:

test06.h
#ifndef TEST06_H
#define TEST06_H

#include
#include "ui_test06.h"
class test06 : public QMainWindow
{
    Q_OBJECT
public:
    test06(QWidget *parent = 0);
    ~test06();
private:
    Ui::test06Class ui;
private:
    void test06::iniTableView();
public slots:
    void test06::slotRowDoubleClicked(const QModelIndex &);
};
#endif // TEST06_H


test06.cpp

#include "test06.h"
#include
test06::test06(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);

    //初期化tableView
    iniTableView();

        //请问slotRowDoubleClicked为什么不能被执行
    connect(ui.tableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotRowDoubleClicked()));
connect(ui.pushButton, SIGNAL(clicked(bool)), this, SLOT(slotRowDoubleClicked()));
        //下面这行代码可以执行,执行结果关闭当前窗口
    //connect(ui.tableView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(close()));
}
void test06::slotRowDoubleClicked(const QModelIndex &)
{
    qDebug("test");
}

void test06::iniTableView()
{
    QStandardItemModel *model = new QStandardItemModel();
    ui.tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui.tableView->setSelectionMode(QAbstractItemView::SingleSelection);
    ui.tableView->setModel(model);
 &#16 ..


#1 [stevenltx 08-24 17:04]
明白了
定义槽是不能加作用域的,改成下面的代码就ok了
public slots:
void slotRowDoubleClicked(const QModelIndex &);

回复 发表
主题 版块