Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] invalid conversion from 'char' to 'char*'



  • @char *argv[30];
    QStringList m; m <<"dd" <<"ss";

    for (int i = 0; i < m.count (); i++)
    argv[i] = (m.at (i).data ())->toLatin1 ();@

    error: invalid conversion from 'char' to 'char*'

    Where should I put & ?



  • @(m.at (i).data ())@ returns QChar*

    @->toLatin1 ()@ returns char. argv[i] is char*.

    i think you want sth like this:
    @argv[i] = m.at(i).toLocal8Bit().data()@



  • [quote author="t3chNo" date="1293294118"]@(m.at (i).data ())@ returns QChar*

    @->toLatin1 ()@ returns char. argv[i] is char*.

    i think you want sth like this:
    @argv[i] = m.at(i).toLocal8Bit().data()@[/quote]

    ... which is completely invalid, you can't store what data() returns!



  • There is one FAQ about the conversion of" QString to char":http://developer.qt.nokia.com/faq/answer/how_can_i_convert_a_qstring_to_char_and_vice_versa see if this is of any help to you.



  • yes, sorry. proper way is:
    @argv[i] = new char[32];
    strncpy(argv[i], m.at(i).toLocal8Bit().data(), 32);@
    [quote author="peppe" date="1293299729"]
    [quote author="t3chNo" date="1293294118"]@(m.at (i).data ())@ returns QChar*

    @->toLatin1 ()@ returns char. argv[i] is char*.

    i think you want sth like this:
    @argv[i] = m.at(i).toLocal8Bit().data()@[/quote]

    ... which is completely invalid, you can't store what data() returns!
    [/quote]



  • It's working :) Thanks
    [quote author="t3chNo" date="1293305300"]yes, sorry. proper way is:
    @argv[i] = new char[32];
    strncpy(argv[i], m.at(i).toLocal8Bit().data(), 32);@
    [quote author="peppe" date="1293299729"]
    [quote author="t3chNo" date="1293294118"]@(m.at (i).data ())@ returns QChar*

    @->toLatin1 ()@ returns char. argv[i] is char*.

    i think you want sth like this:
    @argv[i] = m.at(i).toLocal8Bit().data()@[/quote]

    ... which is completely invalid, you can't store what data() returns!
    [/quote]

    [/quote]


Log in to reply