您的位置:首页 > 移动开发

什么情况下可以不创建QCoreApplication

2011-07-03 12:08 337 查看
UnderwhatcircumstancesdoInotneedtocreatea
QApplication/QCoreApplication?
https://snapbrowse.com/browse.php/Oi8vbGlzdHMudHJvbGx0ZWNoLmNvbS9xdC1pbnRlcmVzdC8yMDA2LTAyL3RocmVhZDAxNTQwLTAuaHRtbA_3D_3D/b0/fnorefer/
Thatnotreallytrueifsaidlikethat.Therearequiteabunchof
classes(forexampleQStringandallthecontainers)whichcanprobably
besafelyusedwithoutaQCoreApplicationobject.Alsobasic
signals/slots
workwithoutQCoreApplication(seeattachedfiles),from
QCoreApplicationsdocumentationitlookstomethataslongasyoudon't
needQt'seventloop(eitherdirectlyoroneoftheclassesyouuse
needsit)yoursafewithouttheQCoreApplicationobject.

HoweverTTrecommendstouseaQCoreApplication,thusaslongasyou
don'twanttoutilizeanotherevent-loop(fromanotherlib)youshould
eitheralreadyknowthatyoudon'tneeditorbetterusea
QCoreApplicationobject.

Andreas

--
[signatureomitted]
#include<myobj.h>
#include<iostream>

intmain(intargc,char*argv[])
{
std::cout<<"Creatingmyobj\n";
myobj*o=newmyobj();
o->method1();
std::cout<<"Deletingmyobj\n";
deleteo;
exit(0);
}

#include<iostream>
#include<iostream>
#include<myobj.h>

myobj::myobj(QObject*parent)
:QObject(parent)
{
connect(this,SIGNAL(signal1()),this,SLOT(slot1()));
}

voidmyobj::method1()
{
std::cout<<"method1ofmyobjcalled\n";
emitsignal1();
}
voidmyobj::slot1()
{
std::cout<<"slot1ofmyobjcalled\n";
}

#include<QObject>
#include<QObject>

classmyobj:publicQObject
{
Q_OBJECT
public:
myobj(QObject*parent=0);
voidmethod1();
publicslots:
voidslot1();
signals:
voidsignal1();
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: