(1) qt 加载dll
QLibrarytestlib("H:\\UltraVNCProjectRoot\\UltraVNCProjectRoot\\UltraVNC\\winvnc\\Debug\\winvnc.dll");
if(testlib.load()){
typedefbool(*lpfun)(char*hostchar,char*IDchar);
lpfunp=(lpfun)testlib.resolve("test");
if(p==NULL)return;
charstrHost[]="10.21.140.39";chartestID[]="666";p(strHost,testID);return;
}
qstring 和LPCWSTR 转换
QString teststring= QDir::currentPath();
files=teststring.split("out",QString::KeepEmptyParts,Qt::CaseSensitive);
QString filepath=files[0].append("/ThirdPartyLib/RemoteTools.dll");
QString filepath=files[0].append("/ThirdPartyLib/VNC/RemoteTools.dll");
hmodule=LoadLibrary((LPCWSTR)filepath.utf16());
qt 隐藏button
ui->pushButton->hide();//隐藏的情况下,没按就保持隐藏
qt 给qpushbutton 设置样式表
用qt designer 打开ui form 选中button 然后属性表设置stylesheet ,复制进去就行了
QPushButton
{
font:bold 17px "微软雅黑";
color: #FFFFFF;
background-color: #46aef2;
border: 0px solid rgba(255,255,255,255);
}
QPushButton:hover{background-color:#ffb82f;}
QPushButton:disabled{background-color:#9c9c9c;color:#c2c2c2;}
qt 获得某一代码目录下的 .CPP 和。h 的文件 的文件数目 qt里面的例子WordCount
QStringList files = findFiles("http://www.cnblogs.com/", QStringList() << "*.cpp" << "*.h");
QStringList findFiles(const QString &startDir, QStringList filters)
{
QStringList names;
QDir dir(startDir);
foreach (QString file, dir.entryList(filters, QDir::Files))
names += startDir + "/" + file;
foreach (QString subdir, dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot))
names += findFiles(startDir + "/" + subdir, filters);
return names;
}
qDebug() << files.count() << "files";
qt获得某一文件下的文字数量
typedef QMap<QString, int> WordCount;
// countWords counts the words in a single file. This function is// called in parallel by several threads and must be thread// safe.
WordCount countWords(const QString &file)
{
QFile f(file);
f.open(QIODevice::ReadOnly);
QTextStream textStream(&f);
WordCount wordCount;
while (textStream.atEnd() == false)
foreach (QString word, textStream.readLine().split(" "))
wordCount[word] += 1;
return wordCount;
}
QString 转成char *
QString requestID;
char* ch;
QByteArray ba = requestID.toLatin1();
ch=ba.data();