Bu sayfayı yazdır
Salı, 21 Mayıs 2013 00:00

QTextstream ile temel işlemler

Yazan 
Öğeyi Oyla
(0 oy)

Aşağıdaki kod ile QTextStream ile yapılan temel işlemleri, nasıl codec ayarlandığını ve C++ benzeri manipulator'ların bir kısmını inceleyebiliriz.

#include < QtCore/QCoreApplication >
#include < QTextStream >
#include < QTextCodec >
#include < QFile >

QTextStream cout(stdout);
QTextStream cin(stdin);
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QString str;
    QTextStream fout(&str);
    cout.setCodec("8859-9");
    int testValue=0x33;
    QFile file("in.txt");
        if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate))
            return 1;

    fout.setDevice(&file);

    const QTextCodec * codec=fout.codec();

    if(codec->name()!="8859-9")
    {
        cout << "Ön tanımlı codec 8859-9 değil 8859-9 olarak ayarlanıyor." << endl;
        fout.setCodec("8859-9");
    }

    fout.setIntegerBase(8);
    fout << "Test Value : " << testValue << " [setIntegerBase(8)]" << reset << endl;
    fout << showbase << forcesign << forcepoint << uppercasebase 
         << "Test Value : " << bin << testValue
         << "[showbase forcesign forcepoint uppercasebase bin]" << "\n"
         << uppercasedigits << lowercasebase << scientific << hex  
         << "Test Value : " << testValue 
         << " [lowercasebase uppercasedigits scientific hex]\n" <<  reset
         << dec << "Test Value : " << testValue << "[reset]" << flush;

    qSetFieldWidth(30);  // Bu kod nedense sonuç üzerinde etki etmedi
    fout << "\n" << 334 << endl;

    fout.setFieldWidth(35);
    fout.setPadChar(QChar(128)); //€ karakteri doldurma karakteri olarak seçiliyor.

    fout << right << "33\n" << left << "33\n" << "\n" << flush;

    //Dikkat edilirse her karakter için setFieldWidth çalışıyor \n için bile
    fout << ws << "\n  Skip Whitespace" << flush;
    //Yukarıdaki ws ile boşlukların gözükmemesini umuyordum. Fakat gözüküyor.!
    
    
    return a.exec();
}



Aşağıda dosya çıktısı bu programın sonucu

Test Value : 63 [setIntegerBase(8)]
Test Value : +0B110011[showbase forcesign forcepoint uppercasebase bin]
Test Value : +0x33 [lowercasebase uppercasedigits scientific hex]
Test Value : 51[reset]
334
€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€33
33
€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€
€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€
  Skip Whitespace€€€€€€€€€€€€€€€€€
Okunma 2710 defa Son Düzenlenme Pazar, 01 Eylül 2013 16:45
Ufuk Yıldırım

Yazılım Geliştirme Uzmanı

Web site: www.ufuk.biz

Son Ekledikleri: Ufuk Yıldırım

Benzer Öğeler (etikete göre)