[Qt-interest] QWidget: Must construct a QApplication before a QPaintDevice

Thiago Macieira thiago at kde.org
Mon Sep 5 17:02:10 CEST 2011


On Monday, 5 de September de 2011 09:59:59 Yifei Li wrote:
> void main()
> {
>      QApplication app();

This is something you just have to learn once:

The above does not declare a variable of name "app", of type QApplication and 
call its default constructor. It declares a variable ot name "app", of the 
type of a function pointer, taking no arguments, and returning a QApplication.

Remove the parentheses.

Compare the errors produced by compiling these two sources:

int main()
{
    QApplication app;
    return app;
}

int main()
{
    QApplication app();
    return app;
}

GCC:
error: cannot convert ‘QApplication’ to ‘int’ in return
error: invalid conversion from ‘QApplication (*)()’ to ‘int’ 

Clang:
error: no viable conversion from 'QApplication' to 'int'
error: cannot initialize return object of type 'int' with an lvalue of type 
'QApplication ()'

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      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/20110905/45fd8d01/attachment.bin 


More information about the Qt-interest-old mailing list