This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Qt Creator 窗体控件自适应窗口大小布局 | |
| 常见的软件窗口大小改变(最大化、手动改变时)需要窗口的部件能够自适应布局,而在Qt的应用程序界面设计中,对于像我一样的初学者如何实现窗口自适应调整还是要绕点弯路的。网上百度了很多,多数说的很含糊,还有很多是用程序实现的,既然已经有Qt Creator那么高集成度的工具了,我还是倾向于直接在Qt Creator中通过可视化配置的方式完成,一是所见即所得,而是效率要高不少。 | |
| Qt中如果想实现窗体内空间随着窗体大小调整,必须使用布局管理,常用的布局管理有QHBoxLayout、QVBoxLayout、QGridLayout,空的地方使用spacer控件进行填充,因此首先将窗体空间使用布局管理典型应用如下图所示。 | |
| image | |
| 我这里使用QGridLayout,按住Ctrl多选需要布局的窗体控件,右键-布局-栅格化局,根据需要进行调整。 | |
| 要想是控件根据窗体进行调整,最为重要的一点就是设置窗口部件的大小策略,各控件均有这一项设置,如下图所示。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __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 中使用的变量。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __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 中使用的变量。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| QString path=QDir::currentPath();//获取程序当前目录 | |
| path.replace("/","\\");//将地址中的"/"替换为"\",因为在Windows下使用的是"\"。 | |
| QProcess::startDetached("explorer "+path);//打开上面获取的目录 | |
| 或者 | |
| QDesktopServices::openUrl(QUrl("file:///C:/Documents and Settings/All Users", QUrl::TolerantMode)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| IplImage转QImage: | |
| [cpp] view plaincopy | |
| QImage* IplImageToQImage(const IplImage *pIplImage) | |
| { | |
| QImage *qImage; | |
| int w = pIplImage->width; | |
| int h = pIplImage->height; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); |