Skip to content

Instantly share code, notes, and snippets.

View 0xlitf's full-sized avatar

0xlitf 0xlitf

  • 22:46 (UTC +08:00)
View GitHub Profile
@0xlitf
0xlitf / QMessageBox
Created February 15, 2016 09:43
QMessageBox
QMessageBox *_msgBox=new QMessageBox;
QPushButton *yes = _msgBox->addButton(QString::fromLocal8Bit("yes"), QMessageBox::YesRole);
QPushButton *no = _msgBox->addButton(QString::fromLocal8Bit("no"), QMessageBox::NoRole);
QPushButton *cancel = _msgBox->addButton(QMessageBox::Cancel);
_msgBox->setText("this file is not saved,\ndo you want to save it?");
_msgBox->exec();
if (_msgBox->clickedButton() == yes)
{
on_action_save_triggered();
m_fileIsSaved = true;
@0xlitf
0xlitf / 在窗体布局中布局
Last active August 24, 2022 02:42
在窗体布局中布局
Qt Creator 窗体控件自适应窗口大小布局
常见的软件窗口大小改变(最大化、手动改变时)需要窗口的部件能够自适应布局,而在Qt的应用程序界面设计中,对于像我一样的初学者如何实现窗口自适应调整还是要绕点弯路的。网上百度了很多,多数说的很含糊,还有很多是用程序实现的,既然已经有Qt Creator那么高集成度的工具了,我还是倾向于直接在Qt Creator中通过可视化配置的方式完成,一是所见即所得,而是效率要高不少。
Qt中如果想实现窗体内空间随着窗体大小调整,必须使用布局管理,常用的布局管理有QHBoxLayout、QVBoxLayout、QGridLayout,空的地方使用spacer控件进行填充,因此首先将窗体空间使用布局管理典型应用如下图所示。
image
我这里使用QGridLayout,按住Ctrl多选需要布局的窗体控件,右键-布局-栅格化局,根据需要进行调整。
要想是控件根据窗体进行调整,最为重要的一点就是设置窗口部件的大小策略,各控件均有这一项设置,如下图所示。
@0xlitf
0xlitf / __declspec关键字详细用法
Last active August 2, 2021 07:54
__declspec关键字详细用法
__declspec关键字详细用法
__declspec用于指定所给定类型的实例的与Microsoft相关的存储方式。其它的有关存储方式的修饰符如static与extern等是C和C++语言的ANSI规范,而__declspec是一种扩展属性的定义。扩展属性语法简化并标准化了C和C++语言关于Microsoft的扩展。
用法:__declspec ( extended-decl-modifier )
extended-decl-modifier参数如下,可同时出现,中间有空格隔开:
align (C++)
allocate
appdomain
deprecated (C++)
dllimport
@0xlitf
0xlitf / __declspec(dllexport) & __declspec(dllimport)
Created February 2, 2016 09:23
__declspec(dllexport) & __declspec(dllimport)
__declspec(dllexport) & __declspec(dllimport)
__declspec(dllexport)
声明一个导出函数,是说这个函数要从本DLL导出。我要给别人用。一般用于dll中
省掉在DEF文件中手工定义导出哪些函数的一个方法。当然,如果你的DLL里全是C++的类的话,你无法在DEF里指定导出的函数,只能用__declspec(dllexport)导出类
__declspec(dllimport)
声明一个导入函数,是说这个函数是从别的DLL导入。我要用。一般用于使用某个dll的exe中
不使用 __declspec(dllimport) 也能正确编译代码,但使用 __declspec(dllimport) 使编译器可以生成更好的代码。编译器之所以能够生成更好的代码,是因为它可以确定函数是否存在于 DLL 中,这使得编译器可以生成跳过间接寻址级别的代码,而这些代码通常会出现在跨 DLL 边界的函数调用中。但是,必须使用 __declspec(dllimport) 才能导入 DLL 中使用的变量。
@0xlitf
0xlitf / __declspec(dllexport) & __declspec(dllimport)
Created February 2, 2016 09:22
__declspec(dllexport) & __declspec(dllimport)
__declspec(dllexport) & __declspec(dllimport)
__declspec(dllexport)
声明一个导出函数,是说这个函数要从本DLL导出。我要给别人用。一般用于dll中
省掉在DEF文件中手工定义导出哪些函数的一个方法。当然,如果你的DLL里全是C++的类的话,你无法在DEF里指定导出的函数,只能用__declspec(dllexport)导出类
__declspec(dllimport)
声明一个导入函数,是说这个函数是从别的DLL导入。我要用。一般用于使用某个dll的exe中
不使用 __declspec(dllimport) 也能正确编译代码,但使用 __declspec(dllimport) 使编译器可以生成更好的代码。编译器之所以能够生成更好的代码,是因为它可以确定函数是否存在于 DLL 中,这使得编译器可以生成跳过间接寻址级别的代码,而这些代码通常会出现在跨 DLL 边界的函数调用中。但是,必须使用 __declspec(dllimport) 才能导入 DLL 中使用的变量。
@0xlitf
0xlitf / qt程序实现打开文件夹
Created January 29, 2016 07:48
qt程序实现打开文件夹
QString path=QDir::currentPath();//获取程序当前目录
path.replace("/","\\");//将地址中的"/"替换为"\",因为在Windows下使用的是"\"。
QProcess::startDetached("explorer "+path);//打开上面获取的目录
或者
QDesktopServices::openUrl(QUrl("file:///C:/Documents and Settings/All Users", QUrl::TolerantMode));
@0xlitf
0xlitf / IplImage与QImage之间相互转换的问题
Created January 29, 2016 06:02
IplImage与QImage之间相互转换的问题
IplImage转QImage:
[cpp] view plaincopy
QImage* IplImageToQImage(const IplImage *pIplImage)
{
QImage *qImage;
int w = pIplImage->width;
int h = pIplImage->height;
@0xlitf
0xlitf / qt log
Created January 28, 2016 10:35
qt log
#include <QtWidgets/QApplication>
#include "idcard_qt.h"
#include<QDebug>
#include <QMessageBox>
#include <qdatetime.h>
#include <qfile.h>
void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
static QMutex mutex;
@0xlitf
0xlitf / CreateThread
Created January 28, 2016 08:44
CreateThread
DWORD WINAPI ThreadProcs_(LPVOID lpParam)
{
char str[1024]={0};
sprintf(str,"上传开始,Id为%s",g_examId.c_str());
LOG4CPLUS_INFO(g_loger,str);
DataProcessWrapper::getInstance()->requestUploadReport(g_examId, NULL);
return 0;
}
@0xlitf
0xlitf / Making an HTTP GET under Qt
Created January 27, 2016 07:43
Making an HTTP GET under Qt
void MainWindow::requestShowPage(){
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(requestReceived(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://google.com")));
}
void MainWindow::requestReceived(QNetworkReply* reply){
QString replyText;
replyText.fromAscii(reply->readAll());