1 Star 0 Fork 0

王泓/deb_maker

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
LibraryGrabberWizardPage3.cpp 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
oosman 提交于 2020-06-24 12:28 . init
#include "LibraryGrabberWizardPage3.h"
#include "ui_LibraryGrabberWizardPage3.h"
#include <QDebug>
#include <QDir>
#include <QProcess>
#include <QStandardItem>
namespace {
QStringList loadedLibraries(int pid)
{
QStringList libs;
QFile maps(QString("/proc/%1/maps").arg(pid));
if(!maps.open(QIODevice::ReadOnly))
{
return libs;
}
for(QString line : maps.readAll().split('\n'))
{
QStringList tokens = line.split(QRegularExpression("\\s+"), QString::SkipEmptyParts);
if(tokens.count() == 6)
{
QString file = tokens.at(5);
if(file.contains(".so") && !libs.contains(file))
{
libs.append(file);
}
}
}
return libs;
}
}//namespace
LibraryGrabberWizardPage3::LibraryGrabberWizardPage3(QWidget *parent)
: QWizardPage(parent)
, ui(new Ui::LibraryGrabberWizardPage3)
, m_model(new QStandardItemModel(1, 1, parent))
{
ui->setupUi(this);
m_model->setHorizontalHeaderItem(0, new QStandardItem("Library"));
ui->tableView->horizontalHeader()->setStretchLastSection(true);
ui->tableView->setModel(m_model);
}
LibraryGrabberWizardPage3::~LibraryGrabberWizardPage3()
{
delete ui;
}
void LibraryGrabberWizardPage3::setPid(int pid)
{
//cat /proc/15407/maps | awk '{print $6}' | grep '\.so' | sort | uniq
auto list = loadedLibraries(pid);
int i = 0;
for(auto file : list)
{
QStandardItem *item = new QStandardItem(file);
// item->setCheckable(true);
// item->setCheckState(Qt::Unchecked);
m_model->setItem(i, 0, item);
++i;
}
}
QStringList LibraryGrabberWizardPage3::selectedLibraries() const
{
QStringList files;
QItemSelectionModel *select = ui->tableView->selectionModel();
if(!select->hasSelection())
{
return files;
}
for(auto idx: select->selectedRows())
{
files.append(m_model->data(m_model->index(idx.row(), 0), Qt::DisplayRole).toString());
}
return files;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kuletco/deb_maker.git
git@gitee.com:kuletco/deb_maker.git
kuletco
deb_maker
deb_maker
master

搜索帮助