Reputation: 218
Hi I'm trying to save entered text from multiple QTextEdit widgets into an object called film of type Film but I don't know how to do it. titleEdit,durationEdit, directorEdit and relDateEdit are all of type QTextEdit. Here is the constructor for Film.
Film::Film(QString t,int dur,QString dir,QDate r):
m_title(t),m_duration(dur),m_director(dir),m_releaseDate(r){
}
And the function that is supposed to take the text entered into the various QTextEdit's and create a film object with the values. Am I on the right track trying to convert the QStrings to plaintext? What do I do with the int? the obtainFilmData function is supposed to save the state of a Film object to a file.
void FilmInput::saveFilm(){
Film film(titleEdit->toPlainText()),durationEdit ,directorEdit->copy(),
relDateEdit->copy());
obtainFilmData(film);
}
Upvotes: 0
Views: 198
Reputation: 12901
I'm assuming here, that all of your input widgets are QTextEdits
.
You can convert QString objects to int. You can do something like this to create your film object:
Film film(titleEdit->toPlainText(), durationEdit->toPlainText().toInt(),
directorEdit->toPlainText(),
QDate::fromString(relDateEdit->toPlainText()), "dd/MM/YYYY"));
Read this to find out about the date formats used in the QDate::fromString(const QString & string, const QString & format)
function.
Upvotes: 1
Reputation: 343
You seem to have an extra parenthesis in here
Film film(titleEdit->toPlainText()**)**,durationEdit ,directorEdit->copy(),
relDateEdit->copy());
There shouldn't be a problem with your constructor either.
Upvotes: 1