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?
Forum Updated to NodeBB v4.3 + New Features

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 920 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 Offline
    M Offline
    Maddy
    wrote on 27 Oct 2022, 11:49 last edited by
    #1

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

    J 1 Reply Last reply 27 Oct 2022, 11:53
    0
    • M Maddy
      27 Oct 2022, 11:49

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

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 27 Oct 2022, 11:53 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 27 Oct 2022, 12:22 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

        J 1 Reply Last reply 27 Oct 2022, 12:23
        0
        • M Maddy
          27 Oct 2022, 12:22

          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

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 27 Oct 2022, 12:23 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 27 Oct 2022, 13:08 last edited by
            #5

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

            J 1 Reply Last reply 27 Oct 2022, 13:09
            0
            • M Maddy
              27 Oct 2022, 13:08

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

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 27 Oct 2022, 13:09 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 27 Oct 2022, 13:19 last edited by
                #7

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

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 27 Oct 2022, 13:32 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 27 Oct 2022, 13:47 last edited by
                    #9

                    How to show random word listwidget using additems?

                    J 1 Reply Last reply 27 Oct 2022, 13:51
                    0
                    • M Maddy
                      27 Oct 2022, 13:47

                      How to show random word listwidget using additems?

                      J Offline
                      J Offline
                      JonB
                      wrote on 27 Oct 2022, 13:51 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 27 Oct 2022, 13:59 last edited by
                        #11

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

                        J 1 Reply Last reply 27 Oct 2022, 14:06
                        0
                        • M Maddy
                          27 Oct 2022, 13:59

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

                          J Offline
                          J Offline
                          JonB
                          wrote on 27 Oct 2022, 14:06 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 27 Oct 2022, 14:23 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));

                            J 1 Reply Last reply 27 Oct 2022, 14:31
                            0
                            • M Maddy
                              27 Oct 2022, 14:23

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

                              J Offline
                              J Offline
                              JonB
                              wrote on 27 Oct 2022, 14:31 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 4 Nov 2022, 09:48 last edited by
                                #15

                                How to use additems?

                                J 1 Reply Last reply 4 Nov 2022, 09:52
                                0
                                • M Maddy
                                  4 Nov 2022, 09:48

                                  How to use additems?

                                  J Offline
                                  J Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 4 Nov 2022, 09:52 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 4 Nov 2022, 10:10 last edited by
                                    #17

                                    the fonts is qstringlist from which i want to display strings

                                    J 1 Reply Last reply 4 Nov 2022, 10:59
                                    0
                                    • M Maddy
                                      4 Nov 2022, 10:10

                                      the fonts is qstringlist from which i want to display strings

                                      J Offline
                                      J Offline
                                      JonB
                                      wrote on 4 Nov 2022, 10:59 last edited by JonB 11 Apr 2022, 11:00
                                      #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