Reputation: 75
I am trying to get a user to type in an address that is comma delimited. The idea is that the program will display the address in a correct format on new lines. I am new to using Qt Creator. I am trying to convert the input to a list and then display the list in a QMessageBox
.
The error I am faced with is:
C:\Qt\5.11.2\mingw53_32\include\QtCore\qstring.h:275: candidate function not viable: no known conversion from '`QStringList`' to '`qlonglong`' (aka '`long long`') for 1st argument
and
C:\Users\Nickitaes\Desktop\Misc\UNISA\COS2614\Assignment 01\header\main.cpp:25: error: no matching conversion for functional-style cast from 'QStringList' to '`QString`'
Below is my code. I'm not sure where I am going wrong and the documentation I have found uses integers.
int main (int argc, char* argv[]) {
QApplication app(argc, argv);
QMessageBox msgBox;
QString enteredAddress = QInputDialog::getText(0, "User Address",
"Enter address each field separated by a comma "
"and a space: ");
QStringList lines = enteredAddress.split(",/n ");
QString response = QString("The new address format is ").arg(lines);
msgBox.setText("Message Box", + QString(enteredAddress.split(",/n")))
return 0;
}
Upvotes: 0
Views: 250
Reputation: 4214
You have multiple typos in your code: e.g., "Message Box", +
should be "Message Box" +
.
Here's a good starting point:
int main (int argc, char* argv[]) {
QApplication app(argc, argv);
QString enteredAddress = QInputDialog::getText(
0,
"User Address",
"Enter address each field separated by a comma and a space: ");
QMessageBox msgBox;
msgBox.setText("Message Box:\n" + enteredAddress.replace(", ", "\n"));
msgBox.show();
return app.exec();
}
Upvotes: 1