Results 1 to 2 of 2

Thread: How to remove this warning: converting 'false' to pointer type for argument QObject*

  1. #1
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    9

    Default How to remove this warning: converting 'false' to pointer type for argument QObject*

    This warning only show when i attributed the false value.

    At windows:
    C:\Users\ricardo\Documents\Thorx\workspace\thx6\2\ src\app\main.cpp:88: warning: converting 'false' to pointer type for argument 2 of 'void QQmlContext::setContextProperty(const QString&, QObject*)' [-Wconversion-null]
    engine.rootContext()->setContextProperty("QT_DEBUG", false);

    At OSX:
    /Users/ricardo/Thorx/workspace/thx6/2/src/app/main.cpp:88: warning: initialization of pointer of type 'QObject *' to null from a constant boolean expression [-Wbool-conversion]
    engine.rootContext()->setContextProperty("QT_DEBUG", false);

    Source code
    Qt Code:
    1. QQmlApplicationEngine engine;
    2. #ifdef QT_DEBUG
    3. engine.rootContext()->setContextProperty("QT_DEBUG", true);
    4. #else
    5. engine.rootContext()->setContextProperty("QT_DEBUG", false);
    6. #endif
    To copy to clipboard, switch view to plain text mode 

    Thanks.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to remove this warning: converting 'false' to pointer type for argument QObje

    The function is overloaded:
    Qt Code:
    1. void QDeclarativeContext::setContextProperty ( const QString & name, QObject * value )
    2. void QDeclarativeContext::setContextProperty ( const QString & name, const QVariant & value )
    To copy to clipboard, switch view to plain text mode 
    You give the compiler a second argument of bool. Since neither overload takes a bool argument explicitly the compiler tries to find a match by casting. In both cases it chooses the QObject* version and issues the warning because using a bool to initialise a pointer is unusual.

    Do this to avoid the warning by forcing the QVariant version:
    Qt Code:
    1. QQmlApplicationEngine engine;
    2. #ifdef QT_DEBUG
    3. engine.rootContext()->setContextProperty("QT_DEBUG", QVariant(true));
    4. #else
    5. engine.rootContext()->setContextProperty("QT_DEBUG", QVariant(false));
    6. #endif
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    ricardodovalle (8th April 2014)

Similar Threads

  1. QObject->inherits() troubles: Keeps returning false
    By JPNaude in forum Qt Programming
    Replies: 6
    Last Post: 3rd March 2010, 08:42
  2. Qt for S60, compiler warning regarding TRUE/FALSE
    By Archimedes in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 22nd October 2009, 14:09
  3. GLib-WARNING **: poll(2) failed due to: Invalid argument.
    By December in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2009, 05:10
  4. default argument compiler warning
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2007, 14:57
  5. Warning QString::arg() argument missing
    By quickNitin in forum Newbie
    Replies: 9
    Last Post: 16th November 2006, 19:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.