1、QT调用cmd命令
void PicturePlay::on_pushButtonBegin_clicked() //实现12张图片复制为90张
{
QProcess p(0);
bool add = false;
int res = 12, index = 13;
QString cmd;
while(index <= 90)
{
if (!add)
{
res--;
if (res == 1)
add = true;
}
else
{
res++;
if (res == 12)
add = false;
}
cmd = "copy C:\\Users\\90970\\Desktop\\20161208_160309\\b" + QString::number(res) + ".bmp C:\\Users\\90970\\Desktop\\20161208_160309\\b" + QString::number(index) + ".bmp";
p.start("cmd", QStringList() << "/c" << cmd);
p.waitForStarted();
p.waitForFinished();
index++;
qDebug()<< index << endl;
}
} 2、QT中实现文件复制
void PicturePlay::on_pushButtonBegin_clicked()
{
bool add = false;
int res = 12, mIndex = 13;
QString newname, oldname;
QString file = dir.absolutePath();
qDebug() << file << endl;
while(mIndex <= 90)
{
if (!add)
{
res--;
if (res == 1)
add = true;
}
else
{
res++;
if (res == 12)
add = false;
}
oldname = file + "/b" + QString::number(res) + ".bmp";
newname = file + "/b" + QString::number(mIndex) + ".bmp";
QFile f(oldname);
f.copy(newname);
mIndex++;
}
} 在QT中调用cmd命令实现复制要指定文件路径,而windows路径中一般使用的是“\\”,容易导致文件写死。