#define CDATABIND_H
#include <QObjectUserData>
class CDatabind : public QObjectUserData
{
public:
CDatabind();
void SetUserData(int ROw, int col);
public:
int m_nRow;
int m_nCol;
};
#endif // CDATABIND_H
#include "cdatabind.h"
CDatabind::CDatabind()
{
m_nRow = -1;
m_nCol = -1;
}
void CDatabind::SetUserData(int row, int col)
{
m_nRow = row;
m_nCol = col;
}
使用
QPushButton *open = new QPushButton("打开");
CDatabind *bindopen = new CDatabind();
bindopen->SetUserData(i, 4);
open->setUserData(0, bindopen);
ui->tableWidget->setCellWidget(i, 4, open);
connect(open, SIGNAL(clicked()), this, SLOT(OnBtnOpendoor()));
QPushButton *lock = new QPushButton("锁定");
CDatabind *bindlock = new CDatabind();
bindlock->SetUserData(i, 5);
lock->setUserData(0, bindlock);
ui->tableWidget->setCellWidget(i, 5, lock);
connect(lock, SIGNAL(clicked()), this, SLOT(OnBtnLockdoor()));
void CDoorctl::OnBtnOpendoor()
{
QPushButton *btn = (QPushButton *)sender();
CDatabind *open = (CDatabind *)btn->userData(0);
int row = open->m_nRow;
int col = open->m_nCol;
int m=0;
}
void CDoorctl::OnBtnLockdoor()
{
QPushButton *btn = (QPushButton *)sender();
CDatabind *open = (CDatabind *)btn->userData(0);
int row = open->m_nRow;
int col = open->m_nCol;
int m=0;
}