静态成员变更量
- aa.h
- class AA
- {
- static char p[13];
- };
- aa.cpp
- char AA::p[13];
如果没在cpp中增加"char AA::p[13];",则编译时会提示"undefined reference to...."的错误
b.h接口中引用a.h接口,使用时必须加上
- include "a.h"
- include "b.h"
否则编译时会出现"如果没在cpp中增加"char AA::p[13];",则编译时会提示"单例模式singleton单元要最先初始化(#include放到最前面)
QWidget类以模式窗体显示:
- dailPage = new DailForm(0,tel);
- dailPage->setWindowModality(Qt::ApplicationModal);
- dailPage->show();
事件过滤写法:
其实可以通过重载QWidget::keyPressEvent()获得本类(假设是窗体)中的几乎所有键盘事件,但焦点在文本框上,就不属于窗体类啦,所以必须采用在窗体类中添加Event Filters:
- CustomerInfoDialog::CustomerInfoDialog(QWidget *parent)
- : QDialog(parent)
- {
- ...
- firstNameEdit->installEventFilter(this);
- lastNameEdit->installEventFilter(this);
- cityEdit->installEventFilter(this);
- phoneNumberEdit->installEventFilter(this);
- }
然后在eventFilter中处理相关键盘事件,通过target判断是否是文本框发生的键盘事件
- bool CustomerInfoDialog::eventFilter(QObject *target, QEvent *event)
- {
- if (target == firstNameEdit || target == lastNameEdit
- || target == cityEdit || target == phoneNumberEdit) {
- if (event->type() == QEvent::KeyPress) {
- QKeyEvent *keyEvent = static_cast(event);
- if (keyEvent->key() == Qt::Key_Space) {
- focusNextChild();
- return true;
- }
- }
- }
- return QDialog::eventFilter(target, event);
- }
去掉窗体标题栏:
- setWindowFlags(Qt::FramelessWindowHint);
- ld.exe cannot find -lSDL
处理:环境变量path加入"D:\QtDevelop\umpcapp\public\SDL-1.2.13\bin"
环境变量path的设置:
- D:\QtDevelop\umpcapp\public\STLport-5.1.3\bin;
- D:\MinGW\bin;
- D:\Qt\bin;
- D:\QtDevelop\umpcapp\public\SDL-1.2.13\bin;
- D:\QtDevelop\umpcapp\public\SDL_mixer-1.2.8\bin
注:STLport-5.1.3一定要放在MinGW前面,不然会出现"QImage: out of memory, returning null image"的错误;如果要用到STLport库,那么在配置.pro文件时,一定要记住把stlport放在其它库的前面,下面的写法是正确的:
- INCLUDEPATH += . \
- ../../public/STLport-5.1.3/stlport \ ###这句一定要放在前面
- ../../public/SDL-1.2.13/include \
- ../../public/common/include \
- ../../public/qextserialport-1.1\
- ../../public/boost-1.37.0/include
如果库的依赖关系(*.dll)出错,则应用程序会出现报内存的错误,最简单的方法就是把应用程序,所需要的库直接加入环境变量path中,以造成如果库更新,原来拷在应用程序下的库没有及时更新,环境变更path的设置例子:
- path += D:\QtDevelop\umpcapp\public\boost-1.37.0\lib;
- D:\QtDevelop\umpcapp\public\qextserialport-1.1\build
上面对应的库为:
- boost_system-mgw34-mt-1_37.dll;boost_thread-mgw34-mt-1_37.dll;
- qextserialport.dll
编译成功后,debug下的exe文件不能生成,请检查.pro文件中,HEADERS与SOURCES参数配置是否有错误,比如把.h文件加入SOURCES参数中,把.cpp加入HEADERS参数中.
- void MapScene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent )
- {
- QPointF scenepos;
- scenepos = mouseEvent->scenePos();
- //qDebug()<
QWebKit中支持Flash播放的代码(Qt4.5才支持Flash)
- webView->page()->settings()->setAttribute(QWebSettings::PluginsEnabled,true);
- listWidget->addItem(new QListWidgetItem(QIcon(":/notepaditem.png"), QFile(files[i]).fileName() ));
vector 引用的单元:
- #include
- using namespace std;
- QString 字符串换行:
- QString str;
- str = tr("133");
- str.append(tr("
- "));
注:br后要加一个空格;
Qss背景透明:
- QPushButton{
- background-color: rgba( 255, 255, 255, 0% );
- }
打开指定URL地址
- QUrl url("http://www.zzwtt.com");
- QDesktopServices::openUrl(url);
可以打开任意URL
窗体置前:
- QWidget w;
- w.setWindowFlags(Qt::WindowStaysOnTopHint);
- w.show();
窗体不显示在任务栏:
- setWindowFlags(Qt::Popup) ;
注:改变*.h的内容,编译时会没有编译过程,只有改变*.cpp才会进行编译;