How to display the numbers in a QList<QString> ?
Hi all,
I am trying to display the multiples of a number using QList<QString> but i was not able to do it on my own.
In my coding when the user enters any number in the input it should display its multiple which means:for example,if the user enters number 4 the output should display the output as:4 8 12 16 20 24 28 32 36 40.
Likewise whenever the user enters any number it should display the output.
This is my code:
void MainWindow:n_pushButton_clicked()
{
int result;
bool ok;
int n1 = ui->lineEdit->text().toInt(&ok,10);
for (int i=1;i<= 10;i++)
{
result = n1 * i;
QList<QString> list ;
list << result;
}
I know that i am wrong somewhere anyone please help me with this?
So that i can know the answer.
Thanks in advance.
Regards,
Harish
Re: How to display the numbers in a QList<QString> ?
Every loop iteration creates new list. These are the basics of C++.
Re: How to display the numbers in a QList<QString> ?
I know that every loop iteration creates new list but i am looking to display each and every value when printed.
I had tried this one now:Is this right ?
void MainWindow:n_pushButton_clicked()
{
int result;
bool ok;
int n1 = ui->lineEdit->text().toInt(&ok,10);
QList<QString> list ;
for (int i=1;i<= 10;i++)
{
result = n1 * i;
QString str;
str.append(QString("%1").arg(result));
list << result;
}
It shows the error: invalid conversion from 'int' to 'const char*' .
Any Solution for this?No one is there to help me?
Re: How to display the numbers in a QList<QString> ?
Bacuse QList<T> have only operator <<(const T & value). So for QList<QString> You can do only <<(QString) not <<(int).
Your code should looks like :
Code:
for (int i=1;i<= 10;i++)
{
result = n1 * i;
}
And please use CODE tags in Your post.
Re: How to display the numbers in a QList<QString> ?
Ok Lesiok thank you for your reply and i will use CODE tags from my post hereafter.
Thank you again..