Qt-interest Archive, April 2007
about QString
Message 1 in thread
hi,all
what the para should be?
i write a c function like this: void sendProgramOpen(char *program);
and call it in qt appliction like this:
QString fileName = QFileDialog::getOpenFileName(this, "Open File", ".",
"G-Code files (*.ngc)");
if (!fileName.isEmpty())
{
loadFile(fileName);
sendProgramOpen(*???*)
}
first , i write the para as "&fileName", the compile error is:
.\mainwindow.cpp(134) : error C2664: 'sendProgramOpen' : cannot convert
paramete
r 1 from 'QString *' to 'char *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-
style cast or function-style cast
then, i modify the para as &fileName.toStdString(), the error as follows:
.\mainwindow.cpp(134) : error C2039: 'toStdString' : is not a member of
'QString'
thanks in advance
regards
fengli
Message 2 in thread
Hi,
> i write a c function like this: void sendProgramOpen(char *program);
1.) Are you sure that you want to write a standard C function?
2.) Is it important to you to pass a "char *"? Why not use unicode-ready
QString?
3.) What Qt-Version are you using?
4.) If it's Qt4, the correct members (as you can read in the docs) are
QString::toAscii(), QString::toLocal8Bit() etc...
Regards,
Malte
--
[ signature omitted ]
Message 3 in thread
hi,
i am using qt4.2.2
to be honest, the c function void sendProgramOpen(char *program) is not
written by me. it's in fact an API of some app. and i just want to call it
in my qt app.
2007/4/10, Malte Witt <malte.witt@xxxxxxxxxxxxx>:
>
> Hi,
>
> > i write a c function like this: void sendProgramOpen(char *program);
>
> 1.) Are you sure that you want to write a standard C function?
> 2.) Is it important to you to pass a "char *"? Why not use unicode-ready
> QString?
> 3.) What Qt-Version are you using?
> 4.) If it's Qt4, the correct members (as you can read in the docs) are
> QString::toAscii(), QString::toLocal8Bit() etc...
>
> Regards,
> Malte
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
Message 4 in thread
> hi,
> i am using qt4.2.2
> to be honest, the c function void sendProgramOpen(char *program) is
> not written by me. it's in fact an API of some app. and i just want
> to call it in my qt app.
Ahh - now it makes sense to me ;-)
Ok, you should be fine with doing something like:
QString myQString("I am the text to pass to sendProgramOpen(char *
apWhatever)");
::sendProgramOpen(myQString.toAscii().data());
Regards,
Malte
--
[ signature omitted ]
Message 5 in thread
*grrr*
> ::sendProgramOpen(myQString.toAscii().data());
Depending on what happens to the "char *" let me correct myself:
QByteArray arrayWithSomeLongerLastingScope = myQString.toAscii();
::sendProgramOpen(arrayWithSomeLongerLastingScope.data());
Malte
--
[ signature omitted ]
Message 6 in thread
I use this and it works fine.
If str is declared as QString str;
Use str.toAscii().constData()
This gives pure char *.
regards,
Ashu
ååä wrote:
> hi,all
> what the para should be?
> i write a c function like this: void sendProgramOpen(char *program);
> and call it in qt appliction like this:
>
> QString fileName = QFileDialog::getOpenFileName(this, "Open File",
> ".", "G-Code files (*.ngc)");
> if (!fileName.isEmpty())
> {
> loadFile(fileName);
> sendProgramOpen(* _???_*)
> }
>
> first , i write the para as "&fileName", the compile error is:
> .\mainwindow.cpp(134) : error C2664: 'sendProgramOpen' : cannot
> convert paramete
> r 1 from 'QString *' to 'char *'
> Types pointed to are unrelated; conversion requires
> reinterpret_cast, C-
> style cast or function-style cast
>
> then, i modify the para as &fileName.toStdString(), the error as follows:
> .\mainwindow.cpp(134) : error C2039: 'toStdString' : is not a member
> of 'QString'
>
> thanks in advance
> regards
> fengli
>
>
--
[ signature omitted ]
Message 7 in thread
Ashutosh Chakraborty wrote:
> I use this and it works fine.
>
> If str is declared as QString str;
>
> Use str.toAscii().constData()
>
> This gives pure char *.
A more compact way of getting a const string is to use qPrintable().
>
> regards,
> Ashu
>
> ååä wrote:
>> hi,all
>> what the para should be?
>> i write a c function like this: void sendProgramOpen(char *program);
>> and call it in qt appliction like this:
>>
>> QString fileName = QFileDialog::getOpenFileName(this, "Open File",
>> ".", "G-Code files (*.ngc)");
>> if (!fileName.isEmpty())
>> {
>> loadFile(fileName);
>> sendProgramOpen(* _???_*)
>> }
>>
>> first , i write the para as "&fileName", the compile error is:
>> .\mainwindow.cpp(134) : error C2664: 'sendProgramOpen' : cannot
>> convert paramete
>> r 1 from 'QString *' to 'char *'
>> Types pointed to are unrelated; conversion requires
>> reinterpret_cast, C-
>> style cast or function-style cast
>>
>> then, i modify the para as &fileName.toStdString(), the error as follows:
>> .\mainwindow.cpp(134) : error C2039: 'toStdString' : is not a member
>> of 'QString'
>>
>> thanks in advance
>> regards
>> fengli
>>
>>
>
--
[ signature omitted ]