QT的点点滴滴Word文件下载.docx
《QT的点点滴滴Word文件下载.docx》由会员分享,可在线阅读,更多相关《QT的点点滴滴Word文件下载.docx(57页珍藏版)》请在冰点文库上搜索。
horizontalHeader()->
setRowHeight(0,25);
setRowHeight(1,25);
setRowCount
(2);
connsql.h
setColumnWidth(0,60);
setColumnWidth(1,100);
if里面的语句要加括号if(条件)
枚举类型的定义:
typedefenum{
nil,
ready,
fired,
exceptional
}Status;
QStringtext=tr("
%1%2"
).arg(i+1).arg(files[i]);
Error:
ISOC++forbidsdeclarationof`NavItem'
withnotype
如果出现以上的错误,其中NavItem是自定义类,则需检查有没Include进此类的定义头文件,
并检查头文件的#ifndef中的名称跟其他类有没重复(在复制其它类生成新类时经常会出现这样的错误)
=====================================================================================
\mingw\lib\libmingw32.a(main.o):
main.c:
(.text+0x104)||undefinedreferenceto`WinMain@16'
|
往pro文件按顺序加入下面三行:
-lmingw32\
-lSDLmain\
-lSDL\
sdl库中文件(sdl.h)里将#include"
SDLMain.h"
注释掉,否则qDebug(),printf全部无法显示
有可能使用#pragmamessage()造成,方法:
不使用#pragmamessage()
========================================================================
cannotopenoutputfiledebug\umpcphonegui.exe:
Permissiondenied
产生此问题是由于文件umpcphonegui.exe受到保护,写不进去,打开任务管理器结束掉此进程就好了
========================================================
pages.h|16|error:
expectedclass-namebefore'
{'
token|
||===Buildfinished:
1errors,0warnings===|
处理方法:
没有include进所需的类
链接时提示"
undefindreferenceto'
vtableforxxx'
错误的处理方法:
重新makefile试下或
工程文件(.pro)中的HEADERS中没有加入定义该类的.h文件;
另一原因,虚函数(或调用的虚函数)定义后没有加"
=0"
intx,y;
setupUi(this);
this->
move(10,60);
resize(338,568);
x=this->
x()+this->
frameGeometry().width();
y=this->
y()+20;
//showMaximized();
rightform=newRightForm;
rightform->
move(x,y);
ERROR:
undefinedreferenceto`RightGpsForm:
RightGpsForm(QWidget*)
工程文件(*.pro)文件中的Source没有加入RightGpsForm类实现的.cpp文件
头部定义有误,需检查头部名称跟文件名是否一样;
尝试重编译
ISOC++forbidsdeclarationof`GPSMainWindow'
withnotype|
类的定义GPSMainWindow(gpsmainwindow.h)中的
#ifndefMAINWINDOW_H_INCLUDED
#defineMAINWINDOW_H_INCLUDED
#include<
QList>
时,提示下面的错误:
QList:
Nosuchfileordirectory
解决方法:
Project-buildoptions-选择整个工程(左侧第一项)--切到右边的页"
Searchdirectories"
增加"
$(#qt4.include)\QtGui\QtCore"
QT中的目录用"
/"
表示
应用程序目录:
QCoreApplication:
applicationDirPath().append(tr("
/world.png"
=========================
QSS:
设置TabWidget中的Tab页高度
QTabBar:
tab{
height:
14ex;
width:
}
======================
TRACE_SUBSYSF(MYRUNLEVEL,MYMODULENAME,QString(QObject:
tr("
测试数据"
))<
<
10);
TRACE_LEVEL=5TRACE_SUBSYS=MAIN/d/study/umpcapp/umpcapp-dev-1.0.0/gpsapp/deb
ug/gpsapp.exe
TRACE_SUBSYSF(5,"
GUIAPP"
QString(QObject:
构造函数创建完毕"
tr("
)<
intret=QMessageBox:
question(this,tr("
提示"
),
tr("
确定要删除文件吗?
QMessageBox:
Yes|QMessageBox:
No,
No);
引用Dll文件(动态链接"
qextserialport.dll"
)时,需在pro里加下面的语句,-l+dll文件名
LIBS+=-lqextserialport
//
//listWidget->
addItem("
a"
);
b"
//QVariantvar;
//var.setValue(newint(789098));
item(0)->
setData(Qt:
UserRole,var);
//int*ptr=listWidget->
data(Qt:
UserRole).value<
int*>
();
//qDebug()<
"
RecentNoteListForm:
<
*ptr<
endl;
//deleteptr;
//delete&
listWidget->
UserRole);
删ITEM方法:
把把ITEM的数据挂到指针上,先删ITEM,然后再删除指针
如果发生nosuchfileordirectorynotfind(报QT核心文件错)
有可能是project--properties--projectssettings中的"
ThisisacustomMakeFile"
没有勾选;
检查.pro文件是INCLUDEPATH+=DEPENDPATH+=有没加入文件所在的目录
检查.pro文件是否引入两个版本不同的相同文件名的文件;
============================================
枚举类型做为信号的参数,则需对枚举类型进行注册
在include中
//定义Enum
typedefenum{
ProgressType,
StartType,
SuccessType,
StopType
}SyncMsgType;
//定义结构
typedefstruct//实际使用中可以多增加些结构成员
{
SyncMsgTypemsgtype;
}SyncMsg;
Q_DECLARE_METATYPE(SyncMsg)
在应用程序.CPP中
//连接之前再注册
qRegisterMetaType<
SyncMsg>
("
SyncMsg"
connect(gpssyncthread,SIGNAL(syncMsgNotify(SyncMsg)),
this,SLOT(syncMsgEvent(SyncMsg)));
========================================
QList<
ItemData*>
listItemDatas;
for(QList<
iteratorit=listItemDatas.begin();
it!
=listItemDatas.end();
++it)
{
(*it)->
colName;
}
==================
multipletypesinonedeclaration
自定义的类{}后面没有"
还有一种可能是pro文件中引用了两次单元文件;
=====================================
expectedunqualified-idbefore"
int"
前一句的"
误写为"
"
======================================
在Bulid工程时,qmake*.pro死循环,原因:
pro文件里同一文件包含两次;
===========================
char*constp;
p所指向的值不能变;
charcont*p;
P所指向的地址不能变;
`nameLineEdt'
wasnotdeclaredinthisscope
函数域没有写;
(函数域:
函数名())
ifdef/define重覆
==============================
intmain(intargc,char*argv[])
Q_INIT_RESOURCE(qtdam);
QApplicationapp(argc,argv);
QSplashScreen*splash=newQSplashScreen;
QStringpath=app.applicationDirPath();
IDIOMA*lang=newIDIOMA();
lang->
setfile_idioma(path+"
/languages.lng"
if(lang->
idioma_seleccionado=="
Españ
ol"
)
splash->
setPixmap(QPixmap("
/images/splash_espagnol.png"
else
/images/splash.png"
show();
Qt:
AlignmenttopRight=Qt:
AlignRight|Qt:
AlignTop;
showMessage(lang->
leer_idioma("
1"
),topRight,Qt:
white);
MainWindowmainWin;
mainWin.show();
finish(&
mainWin);
deletesplash;
returnapp.exec();
===============================
函数如果有返回值必须写,否则有造成一些不确定的错误
如:
QStringa()
QStringstr;
str="
abc"
str.append(a());
QMessageBox:
warning(this,tr("
呼叫"
),str,QMessageBox:
Ok);
上面的情况,对话框可以出来,但点击对话框中的"
确定"
后,程序会死在那;
=====================================================
进行信号连接时,要确保连接参数中的对象已经创建过,否则会报保护错;
图片加载不了,有可能是QT库中的插件库没有拷贝;
加载路径指令:
addLibraryPath(QObject:
%1%2plugins"
).arg(QCoreApplication:
applicationDirPath()).arg("
qDebug()<
插件加载的路径是(QCoreApplication:
libraryPaths):
QCoreApplication:
libraryPaths()<
endl;
有三个插件加载路径1,应用程序路径;
2,QTDIR环境路径,3,加入的路径;
=============================================================
TRACE_LEVEL=5TRACE_SUBSYS=DB/d/study/umpcapp/umpcapp-dev-1.0.0/debug/gpsapp.exe
===============================================
voidDragWidget:
mousePressEvent(QMouseEvent*event)
QLabel*child=static_cast<
QLabel*>
(childAt(event->
pos()));
if(!
child)
return;
QPixmappixmap=*child->
pixmap();
QByteArrayitemData;
QDataStreamdataStream(&
itemData,QIODevice:
WriteOnly);
dataStream<
pixmap<
QPoint(event->
pos()-child->
pos());
=================================================
取得应用程序所在路径,注:
结果后面未加"
applicationDirPath()
===================================================
*.hpp文件,如果改动,Bulid后对改动后代码不起作用,必须ReBulid才可以;
=================================================================
静态成员变更量
aa.h
classAA
staticcharp[13];
};
aa.cpp
charAA:
p[13];
如果没在cpp中增加"
则编译时会提示"
undefinedreferenceto...."
的错误
====================================================================
b.h接口中引用a.h接口
使用时必须加上
include"
a.h"
b.h"
否则编译时会出现"
=========================================================================
单例模式singleton单元要最先初始化(#include放到最前面)
===========================================================
QWidget类以模式窗体显示:
dailPage=newDailForm(0,tel);
dailPage->
setWindowModality(Qt:
ApplicationModal);
================================================================
事件过滤写法:
其实可以通过重载QWidget:
keyPressEvent()获得本类(假设是窗体)中的几乎所有键盘事件,但焦点在文本框上,就不属于窗体类啦,所以必须采用在窗体类中添加EventFilters:
CustomerInfoDialog:
CustomerInfoDialog(QWidget*parent)
:
QDialog(parent)
...
firstNameEdit->
installEventFilter(this);
lastNameEdit->
cityEdit->
phoneNumberEdit->
然后在eventFilter中处理相关键盘事件,通过target判断是否是文本框发生的键盘事件
boolCustomerInfoDialog:
eventFilter(QObject*target,QEvent*event)
if(target==firstNameEdit||target==lastNameEdit
||target==cityEdit||target==phoneNumberEdit){
if(event->
type()==QEvent:
KeyPress){
QKeyEvent*keyEvent=static_cast<
QKeyEvent*>
(event);
if(keyEvent->
key()==Qt:
Key_Space){
focusNextChild();
returntrue;
returnQDialog:
eventFilter(target,event);
========================================================================
去掉窗体标题栏:
setWindowFlags(Qt:
FramelessWindowHint);
==============================================================
ld.execannotfind-lSDL
处理:
环境变量path加入"
D:
\QtDevelop\umpcapp\public\SDL-1.2.13\bin"
===========================
环境变量path的设置:
\QtDevelop\umpcapp\public\STLport-5.1.3\bin;
\MinGW\bin;
\Qt\bin;
\QtDevelop\umpcapp\public\SDL-1.2.13\bin;
\QtDevelop\umpcapp\public\SDL_mixer-1.2.8\bin
注:
STLport-5.1.3一定要放在MinGW前面,不然会出现
QImage:
outofmemory,returningnullimage"
的错误;
==================================================
如果要用到STLport库,那么在配置.pro文件时,一定要记住把stlport放在其它库的前面,
下面的写法是正确的:
INCLUDEPATH+=.\
../../public/STLport-5.1.3/stlport\###这句一定要放在前面
../../public/SDL-1.2.13/include\
../../public/common/include\
../../public/qextserialp