This forum has been archived. All content is frozen. Please use KDE Discuss instead.

KGlobal::locale() and QtTest

Tags: None
(comma "," separated)
Tobias Renger
Registered Member
Posts
5
Karma
0

KGlobal::locale() and QtTest

Mon Nov 08, 2010 8:22 am
Hi,

I run into trouble with QtTest when I want to use classes which call the KGlobal::locale() method (e.g. the constructor of KPIM::KDateEdit). The Problem is KGlobal::locale() returns a null pointer if it is called outside of a KApplication context and so the test will crash. Is there a way how to deal with such classes when working with the test framework of Qt?

Thanks
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: KGlobal::locale() and QtTest

Tue Nov 09, 2010 3:04 am
You need to create a KAboutData and then initialise KCmdLineArgs, using init()

The following code in main() should do the job.

Code: Select all
KAboutData aboutData("appname", 0, ki18n("App Name"), "0.1");
KCmdLineArgs::init(argc, argv, &aboutData);


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
pinotree
KDE Developer
Posts
222
Karma
7
OS
Use one of the QTEST_KDEMAIN* macros instead of QTEST_MAIN. See qtest_kde.h.


Pino Toscano
Tobias Renger
Registered Member
Posts
5
Karma
0

Re: KGlobal::locale() and QtTest

Tue Nov 09, 2010 8:43 pm
pinotree wrote:Use one of the QTEST_KDEMAIN* macros instead of QTEST_MAIN.


Great.
Tobias Renger
Registered Member
Posts
5
Karma
0

Re: KGlobal::locale() and QtTest

Fri Nov 12, 2010 9:14 am
Hi,

it's me again. Thanks for the QTEST_KDEMAIN advice it solved the null pointer problem. But a new problem with KDateTime occured: the KDateTime::toUtc() method doesn't convert the date time to UTC. A short example (my time zone is CET):

Code: Select all
KDateTime dateTime(QDate(2000, 12, 31), QTime(14, 30));
dateTime.toUtc().toString(); //Returns "2000-12-31T14:30:00Z"


With the QTEST_MAIN macro it works correct:

Code: Select all
KDateTime dateTime(QDate(2000, 12, 31), QTime(14, 30));
dateTime.toUtc().toString(); //Returns "2000-12-31T13:30:00Z"


Is this a feature or bug of the QTEST_KDEMAIN macros?


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient