Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. In Q creator how can i compare listwidget index 1 string with string?
Qt 6.11 is out! See what's new in the release blog

In Q creator how can i compare listwidget index 1 string with string?

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 4 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Maddy

    In Q creator how can i compare listwidget index 1 string with string?

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @Maddy Do you mean in Qt? QtCreator is an IDE.

    if (listWidget->item(1)->text() == someString)
    

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • M Offline
      M Offline
      Maddy
      wrote on last edited by
      #3

      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

      jsulmJ 1 Reply Last reply
      0
      • M Maddy

        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

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by jsulm
        #4

        @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...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • M Offline
          M Offline
          Maddy
          wrote on last edited by
          #5

          ok That one is resolved . i want to show item and randomword. how can i do?

          jsulmJ 1 Reply Last reply
          0
          • M Maddy

            ok That one is resolved . i want to show item and randomword. how can i do?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @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...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • M Offline
              M Offline
              Maddy
              wrote on last edited by
              #7

              in listwidget i want to show item and randomword. how can i do?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8

                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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  Maddy
                  wrote on last edited by
                  #9

                  How to show random word listwidget using additems?

                  JonBJ 1 Reply Last reply
                  0
                  • M Maddy

                    How to show random word listwidget using additems?

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #10

                    @Maddy

                    • 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).
                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Maddy
                      wrote on last edited by
                      #11

                      How to pick random word? that what I require to do.

                      JonBJ 1 Reply Last reply
                      0
                      • M Maddy

                        How to pick random word? that what I require to do.

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by JonB
                        #12

                        @Maddy

                        • 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].
                        1 Reply Last reply
                        1
                        • M Offline
                          M Offline
                          Maddy
                          wrote on last edited by
                          #13

                          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));

                          JonBJ 1 Reply Last reply
                          0
                          • M Maddy

                            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));

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #14

                            @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++.

                            1 Reply Last reply
                            1
                            • M Offline
                              M Offline
                              Maddy
                              wrote on last edited by
                              #15

                              How to use additems?

                              jsulmJ 1 Reply Last reply
                              0
                              • M Maddy

                                How to use additems?

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16

                                @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.

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  Maddy
                                  wrote on last edited by
                                  #17

                                  the fonts is qstringlist from which i want to display strings

                                  JonBJ 1 Reply Last reply
                                  0
                                  • M Maddy

                                    the fonts is qstringlist from which i want to display strings

                                    JonBJ Online
                                    JonBJ Online
                                    JonB
                                    wrote on last edited by JonB
                                    #18

                                    @Maddy

                                    @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 to addItems().

                                    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 what addItems() accepts. If you say you want to add a list and are going to call addItems() then there is not much point trying to pass it something like a single item....

                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved