//获得文件对话框中的路径和文件名
QString strDir;
QString strFilename = QFileDialog::getOpenFileName(NULL,"Select file", strDir,"pic file (*.png *.jpg)");
QFileInfo fileInfo(strFilename);
strDir = fileInfo.filepath();
//右键单击,展示菜单
void MyMainWindow::mousePressEvent(QMouseEvent *ev)
{
if(ev->button() == Qt::RightButton)
_menu->exec(QCursor::pos());
}
//右下角托盘程序
#include <QSystemTrayIcon>
QSystemTrayIcon * _icon;
_icon = new QSystemTrayIcon;
_icon->seticon(QIcon("../main.icon"));
_icon->setToolTip("This is tray icon test!");
_icon->show();
connect(_icon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(slotActivated(QSystemTrayIcon::ActivationReason)));
void MyMainWindow::slotActivated(QSystemTrayIcon::ActivationReason reason)
{
if(reason == QSystemTrayIcon::Trigger)
{
if(this->isHidden()) this->show();
else this->hide();
}
}
//显示网卡信息
ChooseInterface::ChooseInterface(QWidget *parent) :
QDialog(parent)
{
/* get all interface */
QList<QHostAddress> addrList = QNetworkInterface::allAddresses();
QList<QNetworkInterface> infList = QNetworkInterface::allInterfaces();
QList<QNetworkAddressEntry> entryList = infList.at(0).addressEntries();
entryList.at(0).broadcast()
foreach(QHostAddress addr, addrList)
{
quint32 ipaddr = addr.toIPv4Address();
if(ipaddr == 0)
continue;
_comboBox->addItem(QHostAddress(ipaddr).toString());
}
}
一、Qt中的进程
#include <QProcess>
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QProcess process;
process.start("ssh root@1.2.3.4");
//多参数:process.start("ssh",QStringList()<<"root@1.2.3.4"<<"-c"<<"-q"
//也可输入参数:process.write()
process.waitForFinished();
qDebug() << process.readAll();
}
二、Qt中的线程
#include <QCoreApplication>
#include <QThread>
int main(int argc, char * argv[])
{
QCoreApplication app(argc,argv);
QThread thread;
thread.start();
}
备份地址: 【Qt知识点收集(二)】