Not sure what all is going on here even after reading it. However I think this might help -
In your save function, if you wanting to prepend or fill blanks up to the text of line edit contents than something like this might be more intuitive:
|
Source code
|
1
2
3
4
5
6
7
|
void MyClassOne::save()
{
QString result;
result.fill( ' ', lineEdit->maxLength() - lineEdit->size() ); // result = " xxxx" based on lineEdit->setMaxLength( 75 );
result += lineEdit->text();
pointerToMyClassTwo->saveToFile(result);
}
|
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
// void MyClassTwo::saveToFile(QString text) // change ->
void MyClassTwo::saveToFile( const QString &text ) // rem update .h
{
QString asterixes;
fill.asterixes( '*', 75 ); // limit from lineEdit?
//
const char * path = filePath.toStdString().c_str() ; // ?? filePath
int number = numberOfLines(path); // ?? numberOfLines()
if(number<=2) createFile(path, asterixes) ; // ?? createFile() of stars or addFile()
// ??
addToFile(path, text) ;
addToFile(path, asterixes) ;
}
|
What is the overall goal of the code above; to wrap a text in stars above and below
and set text right justified in middle, then try something like this:
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
|
QString stars;
stars.fill( '*', 75 );
QFile file( "text.txt" ); // #include <QFile>
if( file.open( QIODevice::Append ) ){
QTextStream textStream( &file ); // #include <QTextStream>
textStream << '\n';
textStream << stars << '\n';
textStream << result << '\n'
textStream << stars << '\n';
file.close();
}
|