Results 1 to 4 of 4

Thread: QImage::bits() overloaded function

  1. #1
    Join Date
    Jun 2008
    Posts
    9
    Thanks
    9
    Platforms
    Unix/X11 Windows

    Default QImage::bits() overloaded function

    Hello!

    In QImage class we have function bits() witch is overloaded:
    Qt Code:
    1. uchar * bits ()
    2. const uchar * bits () const
    To copy to clipboard, switch view to plain text mode 

    My problem is that when I want to call uchar * bits () function, just like that:
    Qt Code:
    1. uchar *bitsImage = image.bits();
    To copy to clipboard, switch view to plain text mode 
    I'm getting an error:
    error: invalid conversion from 'const uchar*' to 'uchar*'

    So I would like to ask how I can call the uchar * bits () function?

    Best regards
    s410i

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QImage::bits() overloaded function

    Quote Originally Posted by s410i View Post
    Hello!

    In QImage class we have function bits() witch is overloaded:
    Qt Code:
    1. uchar * bits ()
    2. const uchar * bits () const
    To copy to clipboard, switch view to plain text mode 

    My problem is that when I want to call uchar * bits () function, just like that:
    Qt Code:
    1. uchar *bitsImage = image.bits();
    To copy to clipboard, switch view to plain text mode 
    I'm getting an error:
    error: invalid conversion from 'const uchar*' to 'uchar*'

    So I would like to ask how I can call the uchar * bits () function?

    Best regards
    s410i
    Although its strange.
    Anyway you can use casting operators. e.g.
    Qt Code:
    1. uchar *bitsImage = const_cast <uchar*> image.bits();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    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: QImage::bits() overloaded function

    Quote Originally Posted by s410i View Post
    So I would like to ask how I can call the uchar * bits () function
    This works fine for me:
    Qt Code:
    1. #include <QImage>
    2.  
    3. int main(){
    4. QImage img;
    5. uchar *bits = img.bits();
    6. return 0;
    7. }
    To copy to clipboard, switch view to plain text mode 

    Your "image" variable is probably const. You can't call non-const methods on a const object.
    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.


  4. The following user says thank you to wysota for this useful post:

    s410i (9th December 2009)

  5. #4
    Join Date
    Jun 2008
    Posts
    9
    Thanks
    9
    Platforms
    Unix/X11 Windows

    Default Re: QImage::bits() overloaded function

    Thank you very much

    const QImage was the problem.

    Best regards
    s410i

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. Regading Driver to connect Postgresql Database
    By dummystories in forum Installation and Deployment
    Replies: 38
    Last Post: 12th March 2009, 07:19
  3. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  4. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

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.