Results 1 to 4 of 4

Thread: pass QByteArray as a pointer

  1. #1
    Join Date
    Apr 2012
    Location
    Hungary, Budapest
    Posts
    9
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default pass QByteArray as a pointer

    Hi,
    How can I pass QByteArray as a pointer.
    My function:
    void removeStars(QByteArray *array){
    //something
    }
    And I am doing this:

    QByteArray array;
    ...
    removeStars(&array);

    I got this error:
    QByteArray:perator QNoImplicitBoolCast() const’ is private

    I tried as it would be char * but it didn’t work too. I mean I used this array like a pointer when I passed it.
    David

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

    Default Re: pass QByteArray as a pointer

    Why do you want to pass a byte array as pointer?

    By the way, the error you are getting is not related to the code you posted.
    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
    Apr 2012
    Location
    Hungary, Budapest
    Posts
    9
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: pass QByteArray as a pointer

    I would like to change 39 QByteArrays one by one.
    I would like to remove some characters from them.
    How can I do it anyway?


    Added after 22 minutes:


    You were right. The problem is not with argument passing.
    I would like to remove ‘*’ from array.
    This is the algorithm:

    void StationsHandler::removeStars(QByteArray *encodedString){

    int size = encodedString->size();
    for (int i = 0; i < size; i++ ){
    if (*(encodedString) == '*'){
    for (QByteArray *temp = encodedString; j < size; j++){
    *(temp) = *(temp+1);
    temp++;
    }
    size--;
    }
    encodedString++;
    }

    *(encodedString+1) = '\0';
    }


    Added after 9 minutes:


    Thank you I have found the problem. You were write the problem was out of this part of code.
    David
    Last edited by David_; 6th December 2012 at 13:30.

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

    Default Re: pass QByteArray as a pointer

    I think you should read about QByteArray::replace() (many variants) and QByteArray::remove() and save yourself a bunch of effort and a whole lot of potential errors.

    Qt Code:
    1. QByteArray toStrip("This contains an * asterisk, maybe more * than one");
    2. qDebug() << toStrip.replace("*", "");
    3. // Output: "This contains an asterisk, maybe more than one"
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 6th December 2012 at 21:23.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

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

    David_ (10th December 2012)

Similar Threads

  1. how to pass a QList pointer
    By ehnuh in forum Qt Programming
    Replies: 2
    Last Post: 5th November 2012, 16:30
  2. Replies: 1
    Last Post: 4th December 2010, 17:20
  3. Replies: 7
    Last Post: 8th August 2010, 09:05
  4. Replies: 14
    Last Post: 1st December 2009, 20:45
  5. Replies: 9
    Last Post: 25th July 2009, 13:27

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.