Storing QTextCharFormat and QColor to text file?
Unsolved
General and Desktop
-
@lansing You can implement
QTextStream & operator<<(const QTextCharFormat&) QTextStream & operator>>(QTextCharFormat&)
and serialise/de-serialise what ever QTextCharFormat properties you want.
See https://doc.qt.io/qt-5/qtextstream.html -
This is my test to write to a text file:
QTextCharFormat textCharFormat; // this has value inside QFile data("output.txt"); if (data.open(QFile::WriteOnly | QFile::Truncate)) { QTextStream out(&data); out << textCharFormat; }
I got an error
invalid operands to binary expression ('QTextStream' to 'QTextCharFormat')
. -
@jsulm said in Storing QTextCharFormat and QColor to text file?:
QTextStream & operator<<(const QTextCharFormat&)
Hi, I have searched around how to write overloaded function for the operator, but I have not seen any example on the syntax you're using.
I have declared
QTextStream & operator<<(const QTextCharFormat&)
in the class' header file, and in the source file, it should be something like this?QTextStream &SettingsDialog::operator<<(const QTextCharFormat &b) { stream << "font: " << b.font().toString() << " font-family: " << b.fontFamily(); return stream; }
But I don't know where do I pass in the
stream
in the implementation.