Results 1 to 3 of 3

Thread: Problem with QString and QByteArray

  1. #1
    Join Date
    May 2011
    Posts
    11
    Thanks
    3
    Qt products
    Qt4

    Default Problem with QString and QByteArray

    Hi all,

    Im am working on a program and have problems with handling a QByteArray string.
    When I try to convert that QByteArray string to a QString with
    Qt Code:
    1. QString newQString = QString(&oldQBytearrayString);
    To copy to clipboard, switch view to plain text mode 
    I do get the following error:

    Qt Code:
    1. error: conversion from ‘QByteArray*’ to ‘QChar’ is ambiguous
    2. /usr/include/QtCore/qchar.h:372:8: note: candidates are: QChar::QChar(int) <near match>
    3. /usr/include/QtCore/qchar.h:371:8: note: QChar::QChar(uint) <near match>
    4. /usr/include/QtCore/qchar.h:370:8: note: QChar::QChar(short int) <near match>
    5. /usr/include/QtCore/qchar.h:81:12: note: QChar::QChar(ushort) <near match>
    6. /usr/include/QtCore/qchar.h:77:36: note: QChar::QChar(uchar) <near match>
    7. /usr/include/QtCore/qchar.h:76:36: note: QChar::QChar(char) <near match>
    To copy to clipboard, switch view to plain text mode 

    The newQString is the output of a script of me and should be a plain text string.

    What is going wrong here?


    Code Snippet:

    myclass.cpp
    Qt Code:
    1. void myclass::Thefunction(){
    2.  
    3. // QProcess *scriptcall; pointer declared as a public member in the class header file
    4. scriptcall = new QProcess(this);
    5. scriptcall -> start("./myscript");
    6.  
    7. connect(scriptcall, SIGNAL(readyReadStandardOutput()), this, SLOT(Readoutput()));
    8.  
    9. }
    10.  
    11. void myclass::Readoutput(){
    12.  
    13. QByteArray oldQByteArrayString;
    14. oldQByteArrayString = scriptcall -> readAllStandardOutput();
    15. QString newQString = QString(&oldQByteArrayString); //this line causes the error
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    Additional Information: I can use oldQByteArrayString with a function that requires QSTtring as a parameter without a problem. (QComboBox::addItem( const QString)). When I look at the hex code of oldQByteArray, it contains exactly what I want to be there - 4 ascii code letters, no special chars.

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Problem with QString and QByteArray

    Take the & off from here:
    QString newQString = QString(&oldQBytearrayString); -> QString newQString = QString(oldQBytearrayString);

    and it should work. A shorter form should also work: QString newQString(oldQBytearrayString);

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Problem with QString and QByteArray

    Why do you want to pass an address of QByteArray to QString constructor ?
    This will work :
    Qt Code:
    1. QString newQString = QString(oldQBytearrayString);
    To copy to clipboard, switch view to plain text mode 
    Last edited by stampede; 10th May 2011 at 21:31. Reason: 2nd

Similar Threads

  1. convert QString to QByteArray
    By morgana in forum Qt Programming
    Replies: 5
    Last Post: 2nd March 2011, 13:33
  2. Part of a QByteArray() to QString()
    By elcuco in forum Qt Programming
    Replies: 1
    Last Post: 4th November 2010, 20:09
  3. QByteArray to QString
    By hvitual in forum Qt Programming
    Replies: 3
    Last Post: 12th December 2009, 10:43
  4. QByteArray to QString
    By babu198649 in forum Newbie
    Replies: 7
    Last Post: 6th December 2007, 13:08
  5. How to get QByteArray from QString in Qt3
    By joseph in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2007, 09:23

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.