[Qt-interest] return to command line but the GUI is still alive
Thiago Macieira
thiago at kde.org
Tue Jan 26 08:31:03 CET 2010
Em Terça-feira 26. Janeiro 2010, às 04.19.06, Forest Yang escreveu:
> > int main(int argc, char** argv)
> > {
> > pid_t pid;
> >
> > pid=fork();
> > if (pid==0)
> > {
> > /* we're the child */
> > QApplication qapp(argc, argv);
> > MainWindow mainWindow;
> > mainWindow.show();
> >
> > qapp.setMainWidget(&mainWindow);
> > qapp.exec();
> > }
> > }
Remember these rules about fork():
1) one side must either execve() or _exit(). That's a strict rule and
independent of Qt.
If neither side does exec (like the example above), then one of the two must
exit via _exit. So the code above is incorrect since both sides exit via
return from main.
2) if you used Qt code before the fork, then only one side of the fork can use
it afterwards. If you managed not to use in either side, then it's ok to use
it in both.
Note that using Qt in static objects counts as using Qt before the fork. This
includes any Qt code that happens before main() as well.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100126/560b8d98/attachment.bin
More information about the Qt-interest-old
mailing list