PDA

View Full Version : Runtime Error



sophister
15th June 2009, 03:45
Hi, I am confused by this problem. When I run my application, a Runtime Error occurs. The following is my main.cpp

#include "userDB.h"
#include "manager.h"
#include "user.h"
#include <QApplication>
#include <QTextCodec>
#include <QPixmap>

UserDB users; //所有已经注册的用户
User currentUser; //当前用户
QPixmap noDishImage; //comment this line, it works fine

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName ("GB2312"));
Manager w;
w.show();
return a.exec();
}
User and UserDB are two classes I write.
Why declaring global variables of my own classes the application works fine, while declaring a blobal variable of the QPixmap leads the application to crash??
Any ideas appreciated!!

nish
15th June 2009, 03:54
You can not declare any QPaintDevice(inherited by QPixmap,QWidget), without initializing QApplication first.

change QPixmap to QPixmap*;


#include <QApplication>
#include <QPixmap>

QPixmap* noDishImage;

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
noDishImage=new QPixmap;
return a.exec();
}

this should work

nish
15th June 2009, 04:04
btw .. what is that Chinese comment?:)

sophister
15th June 2009, 04:09
Yes, it works fine. And I have refer to the Qt doc.
谢谢!!

sophister
15th June 2009, 04:11
uh, my teammates and I are both Chinese, so we use Chinese to comment our code.
That two Chinese comments just tell a reader that what the two global variables are used for.

nish
15th June 2009, 04:14
and what u have written in your last post?

--->谢谢!!<---

sophister
15th June 2009, 04:23
It seems you have little knowledge of Chinese?
Well, 谢谢 means Thank you in English.

nish
15th June 2009, 04:25
i am from India... sadly they dont teach chinese there :(

here in taiwan its called Shiey-Shiey

sophister
15th June 2009, 05:00
You are from India?? you study in Taiwan now?

nish
15th June 2009, 06:28
I am Indian, i work in Hon Hai Precision Ind. (Foxconn), in Taiwan :)