Questions in the path to files instead of Cyrillic.



  • Why did the questions appear in the path to file?

    "D:/My Programs/build-ObservationLog-Desktop_Qt_5_11_0_MSVC2017_64bit-Debug/Журнал_0_Пн_июн_25_2018/Видеокамера/00887.MTS"
    ShellExecute 'file:///D:/My Programs/build-ObservationLog-Desktop_Qt_5_11_0_MSVC2017_64bit-Debug/??????_0_??_???_25_2018/???????????/00887.MTS' failed (error 2).
    

    I changed the compiler from mingw to MSVC2017. After that there was a problem. But this is only an assumption. How to change the code so that links work?

    bool HrefDelegate::editorEvent(QEvent *event,
                                       QAbstractItemModel *model,
                                       const QStyleOptionViewItem &option,
                                       const QModelIndex &index) {
        if ((event->type() == QEvent::MouseButtonRelease) || (event->type() == QEvent::MouseButtonDblClick)) {
            if (index.row()!=0) {
                //QUrl url = index.model()->data(index, Qt::DisplayRole).toUrl();
                QDesktopServices::openUrl(QUrl::fromUserInput(index.model()->data(index, Qt::DisplayRole).toString()));
                return true;
            }
    
        }
        return false;
    }
    

  • Qt Champions 2017

    This post is deleted!

  • Lifetime Qt Champion

    Hi,

    What do you get if you use: index.model()->data(index, Qt::DisplayRole).toString().toUtf8() ?



  • @SGaist If .toUtf8()

    qDebug()<<index.model()->data(index, Qt::DisplayRole).toString().toUtf8();
               QDesktopServices::openUrl(QUrl::fromUserInput(index.model()->data(index, Qt::DisplayRole).toString().toUtf8()));
    
     console:     
    
    "D:/My Programs/build-ObservationLog-Desktop_Qt_5_11_0_MSVC2017_64bit-Debug/\xD0\x96\xD1\x83\xD1\x80\xD0\xBD\xD0\xB0\xD0\xBB_0_\xD0\x92\xD1\x82_\xD0\xB8\xD1\x8E\xD0\xBD_26_2018/\xD0\x92\xD0\xB8\xD0\xB4\xD0\xB5\xD0\xBE\xD0\xBA\xD0\xB0\xD0\xBC\xD0\xB5\xD1\x80\xD0\xB0/00891.MTS"
    ShellExecute 'file:///D:/My Programs/build-ObservationLog-Desktop_Qt_5_11_0_MSVC2017_64bit-Debug/??????_0_??_???_26_2018/???????????/00891.MTS' failed (error 2).
    


  • @SGaist

            ```
    

    QTextCodec *codec_1251 = QTextCodec::codecForName("Windows-1251");
    QString string = codec_1251->toUnicode(index.model()->data(index, Qt::DisplayRole).toByteArray());
    QDesktopServices::openUrl(QUrl::fromUserInput(string));

    Now there are no questions in the path to the file. 
    But :
    

    ShellExecute 'file:///D:/My Programs/build-ObservationLog-Desktop_Qt_5_11_0_MSVC2017_64bit-Debug/Журнал_0_Вт_июн_26_2018/Видеокамера/00884.MTS' failed (error 2).

    ShellExecute  failed (error 2)

  • Qt Champions 2017

    @haifisch said in Questions in the path to files instead of Cyrillic.:

    ShellExecute

    As far as i know it dont like unicode letters. ( its ansi)
    Only ShellExecuteW understands them.



  • @mrjj What do you suggest changing in the code?


  • Qt Champions 2017

    @haifisch
    Hi
    Since you seem to call
    QDesktopServices::openUrl and im not sure we can make it call the W version
    i was wondering if the u thing can fix it.
    https://github.com/inasafe/inasafe/issues/1879
    or if it simply wants
    QDesktopServices::openUrl(QUrl::fromLocalFile(file));



  • @mrjj QDesktopServices::openUrl(QUrl(u"file:///"+index.model()->data(index, Qt::DisplayRole).toString())); Errors, I do not understand how wrapping the url u ''


  • Qt Champions 2017

    Have you tried using your local 8bit encoding, instead of converting it to a unicode?



  • @kshegunov How to convert it to unicode?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.