QT 的点点滴滴

MinGw + CodeBlock + QT4.5

类定义后面要加";"

函数的实现部分,如果定义部分有void,则实现部分不能少;

检查include文件有无少;


error: request for member `show' in `((MainWindow*)this)->MainWindow::rightform', which is of non-class type `RightForm*'|
"->"与"."问题


函数"()"千万不能少;


connect中的SLOT里的自定义过程的申明一定要写在private slots:(或public slots:)下

    QTableWidgetItem *newItemName = new QTableWidgetItem(tr("姓名"));
    newItemName->setFlags(newItemName->flags() & (~Qt::ItemIsEditable));//网格设置为只读
    tblWidgetMingPian->setItem(0, 0, newItemName);

    newItemName = new QTableWidgetItem(tr("陈林
    
    
    
    
    
    & (~Qt::ItemIsEditable));
    tblWidgetMingPian->setItem(0, 1, newItemName);


tblWidgetMingPian->verticalHeader()->hide();
    tblWidgetMingPian->horizontalHeader()->hide();
    tblWidgetMingPian->setRowHeight(0,25);
    tblWidgetMingPian->setRowHeight(1,25);
    
    
        tblWidgetMingPian->setRowCount(2);connsql.h
    tblWidgetMingPian->setColumnWidth(0,60);
    tblWidgetMingPian->setColumnWidth(1,100);
    
    
    if 里面的语句要加括号 if (条件)
    
    枚举类型的定义:
    typedef enum{
        nil,
        ready,
        fired,
        exceptional
    }Status;
    
   
    QString text = tr("%1 %2").arg(i + 1).arg(files[i]);
    
    
Error:ISO C++ forbids declaration of `NavItem' with no type     
如果出现以上的错误,其中NavItem是自定义类,则需检查有没Include进此类的定义头文件,
并检查头文件的#ifndef中的名称跟其他类有没重复(在复制其它类生成新类时经常会出现这样的错误)


=====================================================================================
\mingw\lib\libmingw32.a(main.o):main.c:(.text+0x104)||undefined reference to `WinMain@16' |
往pro文件按顺序加入下面三行:
     -lmingw32 \
     -lSDLmain \
     -lSDL \
     
     sdl库中文件(sdl.h)里将 #include "SDLMain.h" 注释掉,否则qDebug(),printf全部无法显示 
     
     有可能使用 #pragma message()造成,方法:不使用#pragma message()

========================================================================
cannot open output file debug\umpcphonegui.exe: Permission denied
 产生此问题是由于文件umpcphonegui.exe受到保护,写不进去,打开任务管理器结束掉此进程就好了
========================================================

pages.h|16|error: expected class-name before '{' token|
||=== Build finished: 1 errors, 0 warnings ===|
处理方法:没有include进所需的类


链接时提示""undefind reference to 'vtable for xxx'错误的处理方法: 重新makefile试下或
工程文件(.pro)中的HEADERS中没有加入定义该类的.h文件;另一原因,虚函数(或调用的虚函数)定义后没有加"=0";


    int x,y;
    setupUi(this);
    this->move(10,60);
    this->resize(338,568);
    x = this->x() + this->frameGeometry().width();
    y = this->y() + 20 ;
    //showMaximized();
    rightform = new RightForm;
    rightform->move(x,y);


    
ERROR:undefined reference to `RightGpsForm::RightGpsForm(QWidget*)
工程文件(*.pro)文件中的Source没有加入RightGpsForm类实现的.cpp文件
头部定义有误,需检查头部名称跟文件名是否一样;
尝试重编译
    
error: ISO C++ forbids declaration of `GPSMainWindow' with no type|    
类的定义GPSMainWindow(gpsmainwindow.h)中的
#ifndef MAINWINDOW_H_INCLUDED
#define MAINWINDOW_H_INCLUDED
头部定义有误,需检查头部名称跟文件名是否一样;
    
    
#include 时,提示下面的错误:    
QList: No such file or directory   
解决方法:
Project-build options-选择整个工程(左侧第一项)--切到右边的页"Search directories"
增加"$(#qt4.include)\QtGui\QtCore"


QT中的目录用"/"表示

应用程序目录:QCoreApplication::applicationDirPath().append(tr("/world.png"));

=========================
QSS:
设置TabWidget中的Tab页高度
QTabBar::tab {
  height: 14ex;
  width: 14ex;
}


======================
TRACE_SUBSYSF(MYRUNLEVEL,MYMODULENAME,QString(QObject::tr("测试数据"))<<10);

TRACE_LEVEL=5 TRACE_SUBSYS=MAIN /d/study/umpcapp/umpcapp-dev-1.0.0/gpsapp/deb
ug/gpsapp.exe

TRACE_SUBSYSF(5,"GUIAPP",QString(QObject::tr("构造函数创建完毕"))<<10);

TRACE_SUBSYSF(5,"GUIAPP",tr("构造函数创建完毕")<<10);


int ret = QMessageBox::question (this, tr("提示"),
                                         tr("确定要删除文件吗?"),
                                         QMessageBox::Yes | QMessageBox::No,
                                         QMessageBox::No);
                                         
         
引用Dll文件(动态链接"qextserialport.dll")时,需在pro里加下面的语句, -l+dll文件名                                         
LIBS += -lqextserialport    

//
//    listWidget->addItem("a");
//    listWidget->addItem("b");
//    QVariant var;
//    var.setValue (new int(789098));
//
//    listWidget->item(0)->setData(Qt::UserRole,var);
//
//    int* ptr = listWidget->item(0)->data(Qt::UserRole).value < int* >();
//    qDebug()<< "RecentNoteListForm::RecentNoteListForm:" << *ptr << endl;
//    delete ptr;
//    delete &listWidget->item(0)->data(Qt::UserRole);

删ITEM方法:
把把ITEM的数据挂到指针上,先删ITEM,然后再删除指针

                                   
如果发生 no such file or directory not find(报QT核心文件错)
有可能是project --properties--projects settings中的"This is a custom MakeFile"没有勾选;
检查.pro文件是   INCLUDEPATH += DEPENDPATH+= 有没加入文件所在的目录
检查.pro文件是否引入两个版本不同的相同文件名的文件;


============================================
枚举类型做为信号的参数,则需对枚举类型进行注册
在include中
//定义Enum
typedef enum{
    ProgressType,
    StartType,
    SuccessType,
    StopType
}SyncMsgType;
//定义结构
typedef struct  //实际使用中可以多增加些结构成员
{
    SyncMsgType msgtype;
}SyncMsg;


Q_DECLARE_METATYPE(SyncMsg)

在应用程序.CPP中
//连接之前再注册
    qRegisterMetaType("SyncMsg");
    connect(gpssyncthread, SIGNAL(syncMsgNotify(SyncMsg)),
            this, SLOT(syncMsgEvent(SyncMsg)));  
========================================
QList listItemDatas;

 for (QList::iterator it=listItemDatas.begin(); it!=listItemDatas.end() ; ++it)
    {
        (*it)->colName;
    }
    
    
==================    
error: multiple types in one declaration

自定义的类 {}后面没有";"
还有一种可能是pro文件中引用了两次单元文件;
=====================================
expected unqualified-id before "int"
前一句的";"误写为","
======================================

在Bulid工程时,qmake *.pro死循环,原因:pro文件里同一文件包含两次;

===========================


char *const p ; p所指向的值不能变;
char cont *p; P所指向的地址不能变;

===========================
error: `nameLineEdt' was not declared in this scope
函数域没有写; (函数域::函数名())
ifdef/define重覆


==============================
int main(int argc, char *argv[])
{
    Q_INIT_RESOURCE(qtdam);
    
    QApplication app(argc, argv);
    QSplashScreen *splash = new QSplashScreen;
    QString path=app.applicationDirPath();
    IDIOMA *lang = new IDIOMA();
    lang->setfile_idioma(path+"/languages.lng");
    if (lang->idioma_seleccionado=="Español")
        splash->setPixmap(QPixmap(":/images/splash_espagnol.png"));
    else
        splash->setPixmap(QPixmap(":/images/splash.png"));
    splash->show();
    Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
    splash->showMessage(lang->leer_idioma("1"),topRight, Qt::white);
    MainWindow mainWin;
    mainWin.show();
    splash->finish(&mainWin);
    delete splash;
    return app.exec();
}

===============================
函数如果有返回值必须写,否则有造成一些不确定的错误
如: 
QString a()
{
}

QString str;
str = "abc";
str.append(a());
QMessageBox::warning(this, tr("呼叫"),str,QMessageBox::Ok);

上面的情况,对话框可以出来,但点击对话框中的"确定"后,程序会死在那;
=====================================================

进行信号连接时,要确保连接参数中的对象已经创建过,否则会报保护错;


图片加载不了,有可能是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(childAt(event->pos()));
     if (!child)
         return;

     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

你可能感兴趣的:(QT,Qt)