In Q creator how can i compare listwidget index 1 string with string?
-
wrote on 27 Oct 2022, 11:49 last edited by
In Q creator how can i compare listwidget index 1 string with string?
-
@Maddy Do you mean in Qt? QtCreator is an IDE.
if (listWidget->item(1)->text() == someString)
-
wrote on 27 Oct 2022, 12:22 last edited by
Yes in IDE .main.cpp:56:33: Result of comparison against a string literal is unspecified (use an explicit string comparison function instead) his error is coming
-
Yes in IDE .main.cpp:56:33: Result of comparison against a string literal is unspecified (use an explicit string comparison function instead) his error is coming
@Maddy said in In Q creator how can i compare listwidget index 1 string with string?:
his error is coming
Don't you think you should post the code which causes this error?
"Yes in IDE" - your question has nothing to do with the IDE...
-
wrote on 27 Oct 2022, 13:08 last edited by
ok That one is resolved . i want to show item and randomword. how can i do?
-
@Maddy said in In Q creator how can i compare listwidget index 1 string with string?:
i want to show item and randomword
I don't know what this means.
Please explain better... -
wrote on 27 Oct 2022, 13:19 last edited by
in listwidget i want to show item and randomword. how can i do?
-
Hi,
Extract the items in a list, shuffle that list and re-insert the items.
Another way is to use a QListView with a QStringListModel. Shuffle your string list and apply it to the model once done.
-
wrote on 27 Oct 2022, 13:47 last edited by
How to show random word listwidget using additems?
-
wrote on 27 Oct 2022, 13:51 last edited by JonB
- Pick a random word and pass it to void QListWidget::addItem(const QString &label)..
- Or, pick a number of random words, put them in a
QStringList
and pass that to void QListWidget::addItems(const QStringList &labels).
-
wrote on 27 Oct 2022, 13:59 last edited by
How to pick random word? that what I require to do.
-
wrote on 27 Oct 2022, 14:06 last edited by JonB
- Get/choose your source with words in it. I do not know what you intend to do for that.
- Assuming they are in some vector/array. Generate a random integer (Qt has QRandomGenerator Class) between 0 and 1 less than the count of words.
- Pick that word via
vect[random_int]
.
-
wrote on 27 Oct 2022, 14:23 last edited by
i have made qstring fonts then int x as qrandom generator.following is showing an error required ')'.
ui->listWidget_2->addItems("Task 1(RandomWord):" fonts(x)); -
i have made qstring fonts then int x as qrandom generator.following is showing an error required ')'.
ui->listWidget_2->addItems("Task 1(RandomWord):" fonts(x));wrote on 27 Oct 2022, 14:31 last edited by@Maddy said in In Q creator how can i compare listwidget index 1 string with string?:
"Task 1(RandomWord):" fonts(x)
is not a legal expression in C++.
-
wrote on 4 Nov 2022, 09:48 last edited by
How to use additems?
-
@Maddy said in In Q creator how can i compare listwidget index 1 string with string?:
How to use additems?
Please read documentation and learn how to create strings (https://doc.qt.io/qt-6/qstring.html). Also, learn C++.
And please explain what exactly "fonts" is. -
wrote on 4 Nov 2022, 10:10 last edited by
the fonts is qstringlist from which i want to display strings
-
wrote on 4 Nov 2022, 10:59 last edited by JonB 11 Apr 2022, 11:00
@JonB said in In Q creator how can i compare listwidget index 1 string with string?:
Or, pick a number of random words, put them in a QStringList and pass that to void QListWidget::addItems(const QStringList &labels).
is the answer. If you already have a
QStringList
("the fonts is qstringlist ") then pass that toaddItems()
.Your earlier
ui->listWidget_2->addItems("Task 1(RandomWord):" fonts(x));
passes
"Task 1(RandomWord):" fonts(x)
, which is neither a legal C++ expression, nor if it were would it be a list (QStringList
), which is what you say you want to pass and whataddItems()
accepts. If you say you want to add a list and are going to calladdItems()
then there is not much point trying to pass it something like a single item....