QT程序能否如图所示文件名一步传送到位?
本帖最后由 冥界3大法王 于 2022-6-24 12:37 编辑@wanxiangyu
还得请教专家们一个问题哟~~
话说在上一回书中,我们提到的那个贴子中。。
还有一个残留问题没有解决:
我简单的修改了一下代码内容如下:void PatchDialog::on_listModules_itemDoubleClicked(QListWidgetItem *item){ QString str = ui->listModules->currentItem()->text(); //这个编译成功啦~~ Bridge::CopyToClipboard("Patch_" + str); //得到的列表项内容}
然后呢?请看配图 ! 如图所示哈 ~~ 我想让剪贴板的内容一步到位到 文件名中去 !
相关的完整代码如下:
void PatchDialog::on_btnPatchFile_clicked()
{
//get current module
if(!ui->listModules->selectedItems().size())
return;
QString mod = ui->listModules->selectedItems().at(0)->text();
PatchMap::iterator found = mPatches.find(mod);
if(found == mPatches.end()) //not found
return;
PatchInfoList & curPatchList = found.value();
//get patches to save
QList<DBGPATCHINFO> patchList;
for(int i = 0; i < curPatchList.size(); i++)
if(curPatchList.at(i).status.checked)
patchList.push_back(curPatchList.at(i).patch);
if(!curPatchList.size() || !patchList.size())
{
SimpleInfoBox(this, tr("Information"), tr("Nothing to patch!"));
return;
}
if(containsRelocatedBytes(curPatchList) && !showRelocatedBytesWarning())
return;
char szModName = "";
if(!DbgFunctions()->ModPathFromAddr(DbgFunctions()->ModBaseFromName(mod.toUtf8().constData()), szModName, MAX_PATH))
{
SimpleErrorBox(this, tr("Error!"), tr("Failed to get module filename..."));
return;
}
//open the save file dialog
int len = (int)strlen(szModName);
while(szModName != '\\')
len--;
char szDirName = "";
strcpy_s(szDirName, szModName);
szDirName = '\0';
QString filename = QFileDialog::getSaveFileName(this, tr("Save file"), szDirName, tr("All files (*.*)"));
if(!filename.length())
return;
filename = QDir::toNativeSeparators(filename); //convert to native path format (with backlashes)
//call patchSave function
DBGPATCHINFO* dbgPatchList = new DBGPATCHINFO;
for(int i = 0; i < patchList.size(); i++)
dbgPatchList = patchList.at(i);
char error = "";
int patched = DbgFunctions()->PatchFile(dbgPatchList, patchList.size(), filename.toUtf8().constData(), error);
delete [] dbgPatchList;
if(patched == -1)
{
SimpleErrorBox(this, tr("Error!"), tr("Failed to save patched file (%1)").arg(error));
return;
}
SimpleInfoBox(this, tr("Information"), tr("%1/%2 patch(es) applied!").arg(patched).arg(patchList.size()));
}
能否修改如愿呢? 谢谢~~ {:301_974:} 本帖最后由 冥界3大法王 于 2022-6-24 17:22 编辑
现在 只要 在文件名处Ctrl+V 就会得到 【Patch_ + 列表项名】
已经很方便啦~~
能否再向前前进一步呢?
{:301_997:} 本帖最后由 Eaglecad 于 2022-6-24 15:27 编辑
QApplication::clipboard()->setText(str); 这样就把内容自动复制到剪切板了
QApplication::clipboard()->text();这是从剪切板获取内容
char szDirName = "";
strcpy_s(szDirName, szModName);
szDirName = '\0';
这里路径跟上需要保存的文件名,那个文件名就自动出来了
https://imgtu.com/i/jiWfathttps://s3.bmp.ovh/imgs/2022/06/24/fb01d7d2795fcd16.png
页:
[1]