Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. Cast to (void) type
QtWS25 Last Chance

Cast to (void) type

Scheduled Pinned Locked Moved Brainstorm
4 Posts 3 Posters 4.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sabrog
    wrote on last edited by
    #1

    In Qt sources i seeing code:

    @
    (void) new QWhatsThisPrivate;
    @

    @(void) QApplication::sendEvent(this, &mouseEvent;);@

    @(void)::sleep(1);@

    @(void) QLabel::minimumSizeHint();@

    What get this cast to void?

    QT - Apple QuickTime
    Qt - Nokia's Qt Development Frameworks
    Apple is a competitor of Nokia, so QT != Qt

    1 Reply Last reply
    0
    • A Offline
      A Offline
      aavit
      wrote on last edited by
      #2

      Certain compilers would issue a warning on calling functions that are defined to return a value and then ignoring that return value. Casting the return value to void would tell the compiler (and anyone reading the code) that the discarding of it was intentional. So the compilation warning would go away.

      Not sure whether any compilers still have this warning. At least some static code analysers do.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sabrog
        wrote on last edited by
        #3

        Will there be a normal practice to use code like this everywhere?

        I found what Qt have macros Q_REQUIRED_RESULT, but it used only in 2 files:

        • qimage.h
        • qstring.h

        And this work only for GCC. But i think this macros need add to methods wich return pointer to dynamic allocated object what must delete by user like:

        @
        class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject
        {
        ...
        QNetworkReply *head(const QNetworkRequest &request;) Q_REQUIRED_RESULT;
        QNetworkReply *get(const QNetworkRequest &request;) Q_REQUIRED_RESULT;
        QNetworkReply *post(const QNetworkRequest &request;, QIODevice *data) Q_REQUIRED_RESULT;
        QNetworkReply *post(const QNetworkRequest &request;, const QByteArray &data;) Q_REQUIRED_RESULT;
        QNetworkReply *put(const QNetworkRequest &request;, QIODevice *data) Q_REQUIRED_RESULT;
        QNetworkReply *put(const QNetworkRequest &request;, const QByteArray &data;) Q_REQUIRED_RESULT;
        QNetworkReply *deleteResource(const QNetworkRequest &request;) Q_REQUIRED_RESULT;
        @

        From QtAssistant:
        bq. Note: After the request has finished, it is the responsibility of the user to delete the QNetworkReply object at an appropriate time.

        But there is a problem. (void) cast doesn't work anymore with this attribute.

        2Web Community Manager: quotes and code syntax highlighter are broken (artefact ';' after argument of method) :`(

        QT - Apple QuickTime
        Qt - Nokia's Qt Development Frameworks
        Apple is a competitor of Nokia, so QT != Qt

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mgran
          wrote on last edited by
          #4

          [quote author="SABROG" date="1275748540"]
          2Web Community Manager: quotes and code syntax highlighter are broken (artefact ';' after argument of method) :`([/quote]

          We're on it, thanks.

          Project Manager - Qt Development Frameworks

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved