简体   繁体   English

Ubuntu:apt-get install <package> 相当于C ++ apt-pkg库

[英]Ubuntu : apt-get install <package> equivalent in C++ apt-pkg library

I am building a small QT (C++) application where I ask user the software he want to install. 我正在构建一个小型QT(C ++)应用程序,我向用户询问他想要安装的软件。 Once he selected some packages a, b, c from the list all I have to do is run 一旦他从列表中选择了一些包a,b,c,我就必须运行

sudo apt-get install abc sudo apt-get install abc

One way of doing this is using Qprocess or System and run this command directly from C++. 一种方法是使用Qprocess或System并直接从C ++运行此命令。 But I thought this would be a hack and wanted to do using apt-pkg C++ library. 但我认为这将是一个黑客,并希望使用apt-pkg C ++库。 But sadly documentation is very sparse for this library :( I saw source codes of some similar softwares - Software updater ( apt-watch ) etc and found it too complex. Just to run above command, it has lot of code - Initializing pkgCacheFile, PkgIterator, pkgAcqArchive. 但遗憾的是,这个库的文档非常稀疏:(我看到了一些类似软件的源代码 - 软件更新程序(apt-watch)等,发现它太复杂。只是运行上面的命令,它有很多代码 - 初始化pkgCacheFile,PkgIterator ,pkgAcqArchive。

Do I have to do all this to run this simple command ? 我是否必须完成所有这些才能运行这个简单的命令? Isn't there a direct function which takes software name as argument and install it ? 是不是有一个直接的函数,它将软件名称作为参数并安装它? Where Can I get a sample working code for the same ? 我在哪里可以得到相同的样本工作代码?

Thanks 谢谢

I suggest Packagekit . 我建议Packagekit

Here's a link to its documentation page containing some examples 这是包含一些示例的文档页面的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM