当前位置: 技术问答>linux和unix
如何用QT调用linux系统的指令
来源: 互联网 发布时间:2017-01-27
本文导语: 想用QT调用linux里的指令,指令要求光驱弹出然后收回,怎样能够实现。最好能用QT做两个GUI按钮,一个弹出,一个收回。怎么样编写程序啊,哪位高手能帮个忙,本人第一次接触,是菜鸟啊,请哪位大神帮帮我 ...
想用QT调用linux里的指令,指令要求光驱弹出然后收回,怎样能够实现。最好能用QT做两个GUI按钮,一个弹出,一个收回。怎么样编写程序啊,哪位高手能帮个忙,本人第一次接触,是菜鸟啊,请哪位大神帮帮我
|
cdrom.h
cdrom.cpp
#include
#include
class ControlDialog : public QDialog
{
Q_OBJECT
public:
ControlDialog(QWidget* parent = 0);
private slots:
void EjectCdrom();
void CloseCdrom();
private:
QPushButton* buttonEject;
QPushButton* buttonClose;
};
cdrom.cpp
#include
#include
#include
#include "cdrom.h"
ControlDialog::ControlDialog(QWidget* parent)
: QDialog(parent)
{
buttonEject = new QPushButton(tr("Eject"));
buttonClose = new QPushButton(tr("Close"));
connect(buttonEject, SIGNAL(clicked()),
this, SLOT(EjectCdrom()));
connect(buttonClose, SIGNAL(clicked()),
this, SLOT(CloseCdrom()));
QHBoxLayout* mainLayout = new QHBoxLayout;
mainLayout->addWidget(buttonEject);
mainLayout->addWidget(buttonClose);
setLayout(mainLayout);
}
void ControlDialog::EjectCdrom()
{
system("eject /dev/cdrom");
}
void ControlDialog::CloseCdrom()
{
system("eject -t /dev/cdrom");
}
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
ControlDialog* dialog = new ControlDialog;
dialog->show();
return app.exec();
}