===================================================== 进行信号连接时,要确保连接参数中的对象已经创建过,否则会报保护错; 图片加载不了,有可能是QT库中的插件库没有拷贝; 加载路径指令:
QCoreApplication::addLibraryPath(QObject::tr(―%1%2plugins‖).arg(QCoreApplication::applicationDirPath()).arg(―/‖));
qDebug() << ―插件加载的路径是(QCoreApplication::libraryPaths):‖ << QCoreApplication::libraryPaths()< 有三个插件加载路径 1,应用程序路径;2,QTDIR环境路径,3,加入的路径; ============================================================= TRACE_LEVEL=5 TRACE_SUBSYS=DB /d/study/umpcapp/umpcapp-dev-1.0.0/debug/gpsapp.exe =============================================== void DragWidget::mousePressEvent(QMouseEvent *event) { QLabel *child = static_cast QPixmap pixmap = *child->pixmap(); QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << pixmap << QPoint(event->pos() – child->pos()); ================================================= 取得应用程序所在路径,注:结果后面未加‖/‖ QCoreApplication::applicationDirPath() =================================================== *.hpp文件,如果改动,Bulid后对改动后代码不起作用,必须ReBulid才可以; ================================================================= 静态成员变更量 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放到最前面) 错误: ?Singleton‘ is not a template 解决方法: #include ―singleton.hpp‖ using namespace Pattern; =========================================================== 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 } } } 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 ============================== QString 字符串换行: QString str; str = tr(―133″); str.append(tr(― ======================================================= 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才会进行编译; ================================================ 编译win32 中的 dll工程配置方法(以skypebackend为例): 因为工程中的代码全是标准C++的代码,所以编译方式跟QT有点不一样, Project-properties…-Project settings页中的‖This is a custom Makefile‖前面的方框不要勾选; Project-properties…-Build targets 右边中的‖Type‖设置为‖Console application‖(skypebackend为控制台程序) Project-build options-Linker settings页,设置Link libraries内容为:(win32库文件) ..\\..\\..\\..\\MinGW\\lib\\librpcdce4.a ..\\..\\..\\..\\MinGW\\lib\\librpcns4.a ..\\..\\..\\..\\MinGW\\lib\\librpcrt4.a ============== 按回车定位到下一焦点: connect(lineEdit1, SIGNAL(returnPressed()), lineEdit2, SLOT(setFocus())); ======================================= 项目翻译DEMO: #include QApplication app( argc, argv ); QTranslator translator( 0 );//Creates a QTranslator object without a parent translator.load( ―ttl_zh-cn‖, ―.‖ );//Try to load a file called ttl_zh-cn.qm app.installTranslator( &translator );//Add the translations from ttl_zh-cn.qm to the pool of translations QPushButton hello( QPushButton::tr( ―Hello world!‖ ), 0 ); app.setMainWidget( &hello ); hello.show(); return app.exec(); } 1.使用qmake -project生成.pro文件; 2.在.pro文件中加上如下语句: TRANSLATIONS = ttl_zh-cn.ts
‖)); 注:br后要加一个空格;