日志
-
2017-08-24 14:15
-
Qt调用shell脚本
阅读全文»分类:默认分类|回复:0|浏览:799
shell脚本内容如下图所示,那么你需要将内容读到QStringList中,然后在执行。
代码如下
bool CallShell::startCMD()
{
QProcess *cess = new QProcess;
QStringList strlist;
//startHrcommPath_GLOBLE=/home/hrcom/bin/startup.sh
readContent(strlist,startHrcommPath_GLOBLE);
cess->start(startHrcommPath_GLOBLE,strlist);
return true;
}
void CallShell::readContent(QStringList &list,QString path)
{
list.clear();
QFile file(path);
if(!file.open(QIODevice::ReadOnly | QIODevice: ..
-
2016-08-30 17:29
-
QByteArray strData;
阅读全文»分类:默认分类|回复:1|浏览:1024
QDataStream out(&file);
//out<<strData;//这么写有问题,Qt会自动将strData转换成中文,这时如果strData中含有半个中文那么就会出现乱码。
乱码示意图:
解决办法是下面这句代码。
out.writeRawData(strData.data(),strData.length());
-
2016-08-10 19:58
-
for(int i=0;i<10;i++)
阅读全文»分类:默认分类|回复:3|浏览:1680
{
QEventLoop eventloop;
QTimer::singleShot(100, &eventloop, SLOT(quit()));
eventloop.exec();
qDebug()<<"100ms执行一次";
}
详细参考::http://blog.hehehehehe.cn/a/4026.htm
-
2016-08-10 10:26
-
bool DeleteDirectory(const QString &path)
阅读全文»分类:默认分类|回复:0|浏览:1348
{
if (path.isEmpty())
return false;
QDir dir(path);
if(!dir.exists())
return true;
dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);
QFileInfoList fileList = dir.entryInfoList();
foreach (QFileInfo fi, fileList)
{
if (fi.isFile())
fi.dir().remove(fi.fileName());
else
DeleteDirectory(fi.absoluteFilePath());
}
return dir.rmpath(dir.absolutePath());
}
网上找的 亲测好使。
-
2016-08-01 17:38
-
该代码顺带增加了 新建名称后默认按数字顺序排序的功能。例如第一次新建文件应为“XX1"第二次为“XX2”,同时如果当前目录下没有“XX1”则会新建“XX1”而不是“XX3”。说白了就是 验证1、2、3、4、5...是否是连续的 少哪个建哪个
阅读全文»分类:默认分类|回复:1|浏览:981
int num = -1;
QDir dir("./channelconf");
dir.setFilter(QDir::Dirs|QDir::NoDot|QDir::NoDotAndDotDot);//去掉其中.和..
dir.setSorting(QDir::Name);
if(!dir.exists())
{
QMessageBox::information(this,"提示","新建通道路径不存在。");
return num;
}
QFileIn ..
-
2016-08-01 17:26
-
QTreeWidgetItem *item=new QTreeWidgetItem;
阅读全文»分类:默认分类|回复:2|浏览:1108
item->setFlags(item->flags() | Qt::ItemIsEditable);
QTreeWidgetItem * item = ui->treeWidget->currentItem();
ui->treeWidget->editItem(item, 0);
ui->treeWidget->expandToDepth(0);//将一级节点展开(父级)
-
2016-07-11 14:52
-
设置界面背景例如MainWindow 可以直接在cpp中 this->setStyleSheet("border-image:url(:/img/images/mainBj.png)");
阅读全文»分类:默认分类|回复:0|浏览:960
但是这样有弊端,这样就会导致界面中的其他控件全部自动调用该背景,这时有个取巧的办法,可以使用一个QLable将其拖到跟窗口一样大小,然后将其余的控件设置好,最后使用该Qlable的setStyleSheet("border-image:url(:/img/images/mainBj.png)");需要注意的是该Qlable不可使用布局,因为它不是容器,该方法只使用于固定最大大小的窗口,窗口变小则没有关系。
如果想设置大小可以随意变化的呢?很简 ..
-
2016-06-07 15:56
-
#include <stdio.h>
阅读全文»分类:默认分类|回复:1|浏览:1321
#include <string.h>
#include <string>
#ifdef WINDOWS_ENV
#include <winsock2.h>
#include <Iphlpapi.h>
#pragma comment(lib,"Iphlpapi.lib")
#else
#include <sys/ioctl.h>
#include <net/if.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>
#include <unistd.h>
#endif
using std::string;
#ifdef WINDOWS_ENV
void Init_Windows(unsigned char *mac);
#else
void Init_L ..
-
2016-05-04 14:38
-
//键盘按键按下
阅读全文»分类:默认分类|回复:0|浏览:1116
void QDefinTblView::keyPressEvent(QKeyEvent *e)
{
QModelIndexList indexList = this->selectedIndexes();
foreach(QModelIndex index,indexList)
{
if(this->indexWidget(index) != NULL)
{
QTableView::keyPressEvent(e);
return;
}
}
if(e->key()==16777249)
{
Key_Ctrl_Down=true;
}
if(e->key()==Qt::Key_C)
{
if(Key_Ctrl_Down)
{
DoCopy();
}
}
//QTableView::keyPressEvent(e);
}
//键盘按键释放
void QDefinTblView::keyReleaseEvent(QKeyEvent *e)
{
QModelIndexLi ..
-
2016-02-19 14:20
-
代码是从网上找的,其中有几处错误已经改正了。
阅读全文»分类:默认分类|回复:1|浏览:1152
static char ConvertHexChar(char ch)
{
if((ch >= '0') && (ch <= '9'))
return ch-0x30;
else if((ch >= 'A') && (ch <= 'F'))
return ch-'A'+10;
else if((ch >= 'a') && (ch <= 'f'))
return ch-'a'+10;
else return (-1);
}
static QByteArray QString2Hex(QString str)
{
QByteArray senddata;
int hexdata,lowhexdata;
int hexdatalen = 0;
int len = str. ..