Seite 1 von 1

image.save() mit QString format ???

Verfasst: 26. Juni 2006 23:44
von Mati
Hallo,

ich frage mich warum ich bei image.save() kein QString als bildformat übergeben darf?
Ich weiß dass in der Doku das ein const char* sein MUSS aber warum denn?

Ich MUSS unbeding einen QString in einen const char* umwandeln....schaffe das aber nicht.

Gibt es eine Lösung?

Verfasst: 27. Juni 2006 01:19
von patrik08
Habe ich eben vor 2 stunden gemacht...
ich paste mal den code unkommentiert....

http://dictionary.reference.com/translate/text.html

Wenn es nicht verstaendlich ist.... kannst ja nochmals freundlich fragen...

Code: Alles auswählen

void Gui_Resize::SavePicimage()
{
    QString saveto = fileName;
    QFileInfo ImageInfo(saveto);
    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    QString ext = ImageInfo.completeSuffix();
    QByteArray ba = ext.toAscii();
    if (!fileName.isEmpty()) {
            int large = horizontalSlider->value();
            if (large > 151) {
            QPixmap picsa(fileName);
            QPixmap resized = picsa.scaledToWidth(large); 
            resized.save(saveto,ba.data(),80);   
            QApplication::restoreOverrideCursor();                 
            QMessageBox::information(this, tr("Segnalazione:"), tr("Questa immagine è stata correttamente salvata.\nNon dimenticate di salvare il tutto."));               
            } else {
            QApplication::restoreOverrideCursor(); 
            QMessageBox::information(this, tr("Segnalazione:"), tr("Questa immagine %1 figura troppo piccola.").arg(fileName));
            }
    } else { 
    QApplication::restoreOverrideCursor(); 
     QMessageBox::information(this, tr("Segnalazione:"), tr("Impossibile Caricare il file %1.").arg(fileName));   
    }
   QApplication::restoreOverrideCursor();  
}

Re: image.save() mit QString format ???

Verfasst: 27. Juni 2006 06:30
von Christian81
Mati hat geschrieben:Hallo,

ich frage mich warum ich bei image.save() kein QString als bildformat übergeben darf?
Ich weiß dass in der Doku das ein const char* sein MUSS aber warum denn?

Ich MUSS unbeding einen QString in einen const char* umwandeln....schaffe das aber nicht.

Gibt es eine Lösung?
Schonmal mit latin1() / toLatin1().data() versucht??

Verfasst: 27. Juni 2006 08:15
von Alci
Hi, folgendes aus der Doku:
You can also pass string literals to functions that take QStrings and the QString(const char *) constructor will be invoked. Similarily, you can pass a QString to a function that takes a const char * using the qPrintable() macro which returns the given QString as a const char *. This is equivalent to calling <QString>.toAscii().constData().

Verfasst: 27. Juni 2006 14:40
von Mati
Danke euch vielmals!
Jetzt klappts auch bei mir :)

Wenn ich euch nicht hätt :)