Home > Mobile >  Have a QString array in Qt? Beginners Qt, code bug, for help...
Have a QString array in Qt? Beginners Qt, code bug, for help...

Time:09-25

Void BTree: : Read () {
QFile file (" E: \ \ QtProject Tree \ \ \ \ manager. TXT ");
QTextCodec * codec=QTextCodec: : codecForName (" GBK ");
If (file. Open (QIODevice: : ReadWrite))
{qDebug () & lt; <" File can be opened successfully ";

int i=0;
while(! The file, atEnd () & amp; & i<19)
{
QByteArray line=file. ReadLine ();
QString STR (line);

The manage [I]=STR;
i++;
QDebug () & lt; <" "Read elements & lt; & lt; i<& lt; The manage [I];
}
File. The close ();
}
QDebug () & lt; <" Read the success ";
}


The manage is a QString [] array (don't know can use)
Why this code display file is opened, the console output is the blank space

CodePudding user response:

QString array can consider to use QStringList (also seemed QList) Instead, at least, this is more convenient in Qt (anyway, I have never seen a use QString array, use a similar array is QStringList )

CodePudding user response:

Usually we use QStringList or QVector To store the object, if you must use the c way of array
QString manager [16]. This also please defined as QString * manager [16]. At the time of actual use
QString STR=new QString (line);
The manage [I]=STR;
Don't forget to delete after use

CodePudding user response:

Way as to why not directly in c array, in simple terms: array for storage of thing is a thing (f), a QString variable-length calculate is the actual content

CodePudding user response:

Since using QT and c + +, that is proposed to train of thought transformation to object-oriented,
As the second floor, use QStringList can, don't use it, please consult the help manual,
I wish you a speedy skilled use of Qt

CodePudding user response:

Use QVector Or QStringList
  •  Tags:  
  • Qt
  • Related