-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwidget.cpp
More file actions
116 lines (97 loc) · 2.82 KB
/
widget.cpp
File metadata and controls
116 lines (97 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>
#include <QDebug>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
LONG ret = pcsc.apiSCardEstablishContext();
qDebug() << "apiSCardEstablishContext = " << ret;
slotRefreshReaders();
connect(ui->pushButton_refresh,SIGNAL(pressed()),this,SLOT(slotRefreshReaders()));
connect(ui->pushButton_connect,SIGNAL(pressed()),this,SLOT(slotSCardConnect()));
connect(ui->pushButton_disconnect,SIGNAL(pressed()),this,SLOT(slotSCardDisconnect()));
connect(ui->pushButton_transmit,SIGNAL(pressed()),this,SLOT(slotSCardTransmit()));
connect(ui->pushButton_control,SIGNAL(pressed()),this,SLOT(slotSCardControl()));
}
Widget::~Widget()
{
delete ui;
pcsc.apiSCardReleaseContext();
qDebug() << "apiSCardReleaseContext()";
}
void Widget::slotRefreshReaders()
{
ui->comboBox_readerList->clear();
QList<QString> lstReaderName = pcsc.apiSCardListReaders();
qDebug() << "apiSCardListReaders: " << lstReaderName;
ui->comboBox_readerList->addItems(lstReaderName);
}
void Widget::slotSCardConnect()
{
LONG rv = pcsc.apiSCardConnect(ui->comboBox_readerList->currentText(),
SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1);
if(rv != 0)
{
QMessageBox::warning(this, "错误","卡片连接失败");
}
else
{
QMessageBox::information(this, "提示","卡片连接成功");
}
}
void Widget::slotSCardDisconnect()
{
LONG rv = pcsc.apiSCardDisconnect(SCARD_UNPOWER_CARD);
if(rv != 0)
{
QMessageBox::warning(this, "错误","卡片掉电失败");
}
else
{
QMessageBox::information(this, "提示","卡片掉电成功");
}
}
void Widget::slotSCardTransmit()
{
bool ok;
QString send = ui->lineEdit_transmit->text();
if(send != "")
{
ui->label_recv->clear();
QString recv = pcsc.apiSCardTransmit(&ok,send);
if(ok)
{
qDebug() << recv;
ui->label_recv->setText(recv);
}
else
{
QMessageBox::warning(this, "错误","发送失败");
}
ui->lineEdit_transmit->clear();
}
}
void Widget::slotSCardControl()
{
bool ok;
QString send = ui->lineEdit_control->text();
if(send != "")
{
ui->label_recv->clear();
QString recv = pcsc.apiSCardControl(&ok,send);
if(ok)
{
qDebug() << recv;
ui->label_recv->setText(recv);
}
else
{
QMessageBox::warning(this, "错误","发送失败");
}
ui->lineEdit_control->clear();
}
}