Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QString conversion to char format
Qt 6.11 is out! See what's new in the release blog

QString conversion to char format

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    esbxp
    wrote on last edited by
    #1

    Hello :

    I need have this ?

    @char buffer[80] = "";
    sprintf( buffer, "%s%s_04i.%s", "C:\Test\MyImage", "Sector_", index, "png" );
    @

    the result will be :

    @"C:\Test\MyImage\Sector_00000.png
    "C:\Test\MyImage\Sector_00001.png
    "C:\Test\MyImage\Sector_00002.png
    "C:\Test\MyImage\Sector_00003.png
    @

    hmm ... but then the dialog "lineEdit", return a QString ...

    @
    QString strCache = ui->edt_CachePath.text() //. Return QString not char;
    QString strSector = ui->edt_CacheSector.text() //. Return QString not char;

    QString strResult = "";

    for(int index = 0; index< 1000; index+=1) {
    QtextStram(&strResult) << strCache << "/" << strSector << index << ".png";
    strResult = "";
    }
    @

    the result is:

    @
    "C:\Test\MyImage\Sector_8.png"
    "C:\Test\MyImage\Sector_9.png"
    "C:\Test\MyImage\Sector_10.png"
    "C:\Test\MyImage\Sector_11.png"

    //. Remember sprintf () is : "C:\Test\MyImage\Sector_00008.png"
    @

    how for fill Zeros in QString,,,
    and how Convert QString to char ??

    1 Reply Last reply
    0
    • E Offline
      E Offline
      esbxp
      wrote on last edited by
      #2

      Hello:
      Sorry I Find the Alternative Solution .... Thanks !!!

      @
      #include <QCoreApplication>
      #include <QDebug>

      int main(int argc, char *argv[])
      {
      QCoreApplication a(argc, argv);

      QString strResult = "";
      QString strCaches = "C:\\Test\\MyFolder";
      QString strPrefix = "Sector_";
      
      //. [1]
      for(int index=0; index<10; index+=1){
          strResult = QString("Sector_%1").arg(index,5,10,QLatin1Char('0'));
          qDebug() << strResult;
      }
      
      qDebug() << " ---------- Case 2 -------------- ";
      //. [2]
      for(int index=0; index<10; index+=1){
          strResult = QString("%1\\%2%3").arg(strCaches).arg(strPrefix).arg(index, 5, 10, QLatin1Char('0'));
          qDebug() << strResult;
      }
      
      return a.exec&#40;&#41;;
      

      }
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved