函数在Qt中无法正常工作

function is not working properly in Qt

本文关键字:常工作 工作 Qt 函数      更新时间:2023-10-16

我正在制作一个简单的 GUI 程序来更改 android 手机的启动动画,但从最近 4 天开始,我遇到了一个问题,我不知道什么是原因,这是我的代码

void MainWindow::bootanim1()
{   
    QProcess rootboot;
    QStringList path6,boottarget;
    path6<<ui->lineEdit_6->text();
    boottarget<<path6<<" /system/media";
    ui->textBrowser->clear();
    ui->textBrowser->setText("Remounting partitions...");
    rootboot.start("bbin\adb shell su -c "busybox mount -o remount,rw /system"");
    rootboot.waitForFinished();
    ui->textBrowser->setText("nInstalling bootanimation.zip");
    rootboot.start("bbin\adb push ",boottarget);
    rootboot.waitForFinished();
    ui->textBrowser->setText("nBootanimation has been changed! Try shutting down your phone to see new bootanimation");
}

单击按钮时启动此功能,但我的问题是,这不起作用!其次,您可以在代码中看到,为了提供更多信息,我使用了一个textBrowser向用户显示正在发生的事情,例如重新挂载分区等,lineEdit_6lineEdit小部件,用户将在其中粘贴引导动画的路径.zip。所以我的问题是当我单击按钮时,仅显示此内容

Bootanimation has been changed! Try shutting down your phone to see new bootanimation

我认为上面的所有内容都被跳过了,我不知道为什么? 谁能给我一些提示我错过了什么?

在这里,您混合了两种不同的方法来为 QProcess 提供参数:

boottarget<<path6<<" /system/media";
rootboot.start("bbin\adb push ",boottarget);

第一种方法在一个QString中给出程序名称和参数。

第二种方法给出 QStringList 中的参数。

您正在尝试在程序名称字符串中给出一个参数("push")。当其他参数在 QStringList 中给出时,它不起作用。最后一个参数在开头也包含可疑的外观空间,尽管我不知道它是否会导致问题。试试这个:

QStringList args;
args << "push" << path6 << "/system/media";
rootboot.start("bbin\adb", args);

path6 变量可能应该是 QString 而不是 QStringList。

Ui 需要 eventloop 来刷新自身。当您在一个函数调用中执行所有更改时,只有内部属性会更改,并且 gui 本身不会重新绘制。每次ui->textBrowser->setText(...);后立即使用QCoreApplication::processEvents();