×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    13

    Copy QString to text file

    I need to save QString (video variable , for example = "rtsp://v1.cache6.c.youtube.com/CjYLENy73wIaLQl7wJwlEuu8vRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYJCCmb7WpIzYTQw=/0/0/0/video.3gp") to external text file (video.ram). I've tried with:

    Code:
        QFile file("E://video.ram");
        file.open(QIODevice::WriteOnly | QIODevice::Text);
        QTextStream out(&file);
    
        QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
        QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    
        out.setCodec(QTextCodec::codecForName("UTF-8"));
        
        //QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        //const QByteArray encodedString = codec->fromUnicode(video);
        //const char *message = encodedString.constData();
        //out << message << endl;
    
        QByteArray enc=video.toUtf8(); 
       
        char *message=new char[enc.size()+1];
    
        strcpy(message,enc.constData());
    
        out << message<< endl;
        file.close();
    I hope that someone can help me! I struggled with this for a long, long, time.

  2. #2
    Registered User
    Join Date
    May 2009
    Location
    Rome
    Posts
    268

    Re: Copy QString to text file

    that works for me ...

    QString token;
    void IdentityProvider::saveToken(){
    QFile *file = new QFile(name+".dat");
    if (file->open(QIODevice::WriteOnly)) {
    QDataStream out(file);
    out << token;
    file->close();
    }
    delete file;
    }

    void IdentityProvider::loadToken(){
    QFile *file = new QFile(name+".dat");
    if (file->open(QIODevice::ReadOnly)) {
    QDataStream in(file);
    in >> token;
    file->close();
    }
    delete file;
    }
    Keep it simple, stupid
    borg - http://store.ovi.com/content/116105

Similar Threads

  1. Replies: 4
    Last Post: 2010-12-31, 09:00
  2. direct copy a file from resource(jar file) to memory card
    By universoft in forum Mobile Java General
    Replies: 1
    Last Post: 2010-01-10, 13:39
  3. Replies: 1
    Last Post: 2009-02-12, 07:29
  4. copy text from sms to midlet
    By mugiwara in forum Mobile Java General
    Replies: 6
    Last Post: 2008-10-03, 19:39

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×