在Qt下面open按键,总是提示open失败。我在dev下面看到有buttons设备啊,而且cat时也是有反应的。
在Qt下面如果我换成open(pwm,0),就成功。不知道为什么啊。
源码如下:
#include "mainwidget.h"
#include "ui_mainwidget.h"
#include <QWSServer>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <qapplication.h>
#include <qmessagebox.h>
#include <qsocketnotifier.h>
int m_fd;
QSocketNotifier *m_notifier;
bool m_oldButtonsState[8];
mainWidget::mainWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::mainWidget)
{
ui->setupUi(this);
set_dialog = NULL;
connect(ui->setButton, SIGNAL(clicked()), this, SLOT(on_setButton_clicked()));
m_fd = ::open("/dev/buttons", 0);
if (m_fd < 0)
{
QMessageBox::information(this, "Error", "Fail to open /dev/buttons.");
return;
}
memset(m_oldButtonsState, 0, sizeof m_oldButtonsState);
m_notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
}
mainWidget::~mainWidget()
{
delete ui;
::close(m_fd);
}
void mainWidget::on_setButton_clicked()
{
if (set_dialog == NULL)
set_dialog = new setDialog(this);
// QWSServer::setCursorVisible(false); //hide the cursor
// set_dialog->setWindowFlags(Qt::FramelessWindowHint);
set_dialog->show();
}