1

I've been trying to create a random phrase generator, which reads nouns from one text file and verbs from another text file. That all worked, but now I'm trying to write a method that capitalizes the first letter of the subject, but keep getting the errors

error: C2248: 'QByteArray::operator QNoImplicitBoolCast' : cannot access private member declared in class 'QByteArray'

see declaration of 'QByteArray::operator QNoImplicitBoolCast'

see declaration of 'QByteArray'

I'll post the code for the method (sorry if its not in proper format I'm new)

    void MainWindow::returnCap(QString sub){

        char *str;
        QByteArray ba;
        ba = sub.toLatin1();
        str = ba.data();
        QString firstLetter;
        firstLetter = str[0];
        QString cappedFirstLetter;
        cappedFirstLetter = firstLetter.toUpper();
        char flc; //firstLetterChar
        flc = cappedFirstLetter.toLatin1();
        str[0] = flc;
    }

Thanks for any help!

ArcWalrus
  • 33
  • 1
  • 7

2 Answers2

1

The problem is that you assigning a byte array to a single character. However you need only one character from the byte array:

char flc; //firstLetterChar
flc = cappedFirstLetter.toLatin1()[0];

UPDATE:

I would solve your problem in the following way:

QChar c1 = sub[0];
c1 = c1.toUpper();
sub.replace(0, 1, c1);
vahancho
  • 20,808
  • 3
  • 47
  • 55
0

You call the member function toLatin1, which returns a QByteArray. You then assign this QByteArray object to a char variable (not char*, just char).

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621