Results 1 to 3 of 3

Thread: How the QReadLocker construction forces to give a variable name?

  1. #1
    Join Date
    Mar 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How the QReadLocker construction forces to give a variable name?

    Hi all,

    I would like to do the same as QT when for some class it is obliged to give a variable name.
    For example QReadLocker, QWriteLocker, QMutexLocker.

    It is not possible to declare

    Qt Code:
    1. QReadWriteLock *myReadWriteLock = new QReadWriteLock();
    2. QReadLocker( myReadWriteLock );
    To copy to clipboard, switch view to plain text mode 

    but you have to give a variable name

    Qt Code:
    1. QReadWriteLock *myReadWriteLock = new QReadWriteLock();
    2. QReadLocker myReadLocker( myReadWriteLock );
    To copy to clipboard, switch view to plain text mode 

    How is it achieved? I can't figure what in the code is done to obtain this behaviour.

    Thanks for your help, I am delighted to learn something new in c++!

    -- pium

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How the QReadLocker construction forces to give a variable name?

    I don't think the code has anything to do with this. It's a matter of the C++ standard that
    Qt Code:
    1. QReadLocker(myReadWriteLock);
    To copy to clipboard, switch view to plain text mode 
    is interpreted as
    Qt Code:
    1. QReadLocker myReadWriteLock;
    To copy to clipboard, switch view to plain text mode 
    in this context.

    The same happens here:
    Qt Code:
    1. #include <stdio.h>
    2.  
    3. int main(int argc, char **argv) {
    4. int (v) = 0;
    5. printf("%d\n", (((((v))))));
    6. return (0);
    7. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How the QReadLocker construction forces to give a variable name?

    hum, arf...

    I haven't seen that, because in my case I have 2 parameters.

    MyClass(param1,param2);

    It is compiling and working (but of course, the destructor is call right after the constructor since the variable can't be used)
    And I'd like to block this kind of call, but it is certainly not possible.

    Thanks for your remark

Similar Threads

  1. what should I give url?
    By sups in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2011, 00:22
  2. QAbstractScrollArea forces repainting the whole viewport
    By Charletes in forum Qt Programming
    Replies: 9
    Last Post: 8th December 2010, 13:25
  3. Hi all. I give up (not really, but yes, kind of)
    By tachoknight in forum Newbie
    Replies: 1
    Last Post: 4th December 2010, 03:57
  4. Non-modal dialog forces app to exit.
    By vereteran in forum Newbie
    Replies: 1
    Last Post: 17th October 2009, 09:39
  5. Number formatting for file name construction
    By philwinder in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2008, 11:57

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.