检查adb是否已安装

时间:2016-09-15 17:30:28

标签: c++ qt

在Qt中,我想检查 import UIKit class ViewController: UIViewController { var orangeSquare: UIView? var animator: UIDynamicAnimator? override func viewDidLoad() { super.viewDidLoad() func sliderChanged(sender: AnyObject) { var sliderValue = sender.value } //Create animation let dim = CGRectMake(100, 500, 200, 100) orangeSquare = UIView(frame: dim) orangeSquare?.backgroundColor = UIColor.orangeColor() //Add item to the screen self.view.addSubview(orangeSquare!) //Initialize the animator animator = UIDynamicAnimator(referenceView: self.view) //Add gravity let gravity = UIGravityBehavior(items: [orangeSquare!]) let direction = CGVectorMake(0.0, sliderValue) gravity.gravityDirection = direction //Collision let boundries = UICollisionBehavior(items: [orangeSquare!]) boundries.translatesReferenceBoundsIntoBoundary = true //Add animations animator?.addBehavior(boundries) animator?.addBehavior(gravity) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } 中的adb命令是否有效( - >已安装)。我已尝试使用cmdsystem,但无法获取有关process是否可以投放的任何信息。

1 个答案:

答案 0 :(得分:1)

我能想到的解决方案是迭代PATH环境变量中的所有目录,并检查adb文件是否存在。

QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QStringList dirs = env.value("PATH").split(":");
foreach(QString p, dirs){
    QFileInfo check_file(p + "/" + "adb");
    if (check_file.exists() && check_file.isFile()) {
        qDebug() << "Yes!";
    }
}

顺便说一句,我在我的linux机器上测试过并且工作正常。

在Windows计算机上,您需要将adb替换为adb.exe,将:替换为;