How can i get QString fileName which contains a name of a opened file, to be stored in
char file[] = ""; ?
so that file[] stores the Qstring value of fileName
thx.
How can i get QString fileName which contains a name of a opened file, to be stored in
char file[] = ""; ?
so that file[] stores the Qstring value of fileName
thx.
Convert that QString to QByteArray and use QByteArray::data() (remember that the returned pointer will be valid only while that QByteArray exists).
Can you write me example how can i convert QString to QByteArray ?
http://doc.trolltech.com/4.1/qstring.html
Look for methods that return QByteArray.
Brrr, i dont get this QT doc at all, some help please
Bah i dont get docs correctly it seems:
QByteArray fil;
fileName.append(fil);
char *file = fil.data();
fileName is defined in .h file as QString fileName and it gets value later.
If i have done that what i wrote above i get in file nothing.
What have i read wrong in docs. Would need s example explanation of docs too
Tried this aswell: char *file2 = fileName.toAscii().data(); also get empty.
Found the problem. I have defined QString fileName; in .h as private. Now i assign a value to it in function when i open the file. But how do i acess it in another function ? I thought its already visible inside that function, but its not, its empty, so how do i assigne the value in that function so i can see it in another function too. Now i get the value like this:
QString fileName = QFileDialog::getOpenFileName(this,tr("Open File"), QDir::currentPath());
In function which i read the file. So how do i see the same string in another function ??
Here you create a new fileName variable, if you have declared fileName as a member variable of your class, use this:Originally Posted by GodlikeQt Code:
To copy to clipboard, switch view to plain text mode
Yep, works like a charm. Thanx again.
Because you create a temporary QByteArray that immediately goes out of scope and leaves file2 as a dangling pointer.Originally Posted by Godlike
There was a thread about this problem, but I can't find it now.
Qt Code:
char *file2 = qstrdup( data.data() );To copy to clipboard, switch view to plain text mode
Bookmarks