有的时候在嵌入式编程过程中无法避免使用命令行直接读取驱动的值。
举例:
QFile file("/root/iovalue.txt");
system("cat /sys/class/gpio/gpio118/value > /root/iovalue.txt");
file.open(QIODevice::ReadOnly | QIODevice::Text);
btnstate=file.readAll();
file.close();
Stop=btnstate.toInt();
qDebug()<<Stop;
这个代码只能读取当前打开文件的内容,如果文件内容更新了,需要再次调用这个函数。当然因为system命令会阻塞进程,所以可以使用Qprocess单独开个进程去做这个事情。