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. Unable to display items of QListWidget
Forum Updated to NodeBB v4.3 + New Features

Unable to display items of QListWidget

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 6.6k 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.
  • E Offline
    E Offline
    endla.ravi
    wrote on last edited by
    #1

    Hi...

    I have a problem in displaying the QListWidget ..

    When i have create the QListWidget from the drag and drop menu..and used like this

    @ui->listWidget->addItem("Hello") @

    ,its working fyn and displaying int the form when i execute.

    But if i do the same in this manner,

    @QListWidgetItem q1=new QListWidgetItem("hello",list,i);

    ui->listWidgetItem->addItem(q1); @

    The above code compiles with no errors,but in the list widget i am unable to find the item.

    Does anyone please sort out this problem..

    Thanks in advance....

    [edit: Code highlighting / Vass]

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      You forgot * before pointer variable(before q1 variable)

      --
      Vasiliy

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vcsala
        wrote on last edited by
        #3

        I was thinking on the same but I am really suprised that it provides clean compile...

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vsorokin
          wrote on last edited by
          #4

          [quote author="VCsala" date="1292775020"]I was thinking on the same but I am really suprised that it provides clean compile...[/quote]

          Me too, I tested it just. My compiler said:

          bq.
          conversion from ‘QListWidgetItem*’ to non-scalar type ‘QListWidgetItem’ requested

          --
          Vasiliy

          1 Reply Last reply
          0
          • E Offline
            E Offline
            endla.ravi
            wrote on last edited by
            #5

            i forgot to put a * there,i actually put it in my program,missed it out here..

            it is

            @
            QListWidgetItem *q1=new QListWidgetItem(“hello”,list,i);
            @

            [edit: Code highlighting / Vass]

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vcsala
              wrote on last edited by
              #6

              It is a good idea (at least for the next time) to use '@' around your code which makes syntax highlighted and more readable.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vcsala
                wrote on last edited by
                #7

                [quote author="endla.ravi" date="1292774037"]ui->listWidgetItem->addItem(q1);[/quote]

                Is this correct (listWidgetItem or listWidget)?

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vsorokin
                  wrote on last edited by
                  #8

                  Show more code, please.
                  I don't understand, what is i  , what is list, why you set parent list, but adding item to ui->listWidget

                  --
                  Vasiliy

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vcsala
                    wrote on last edited by
                    #9

                    I think this should look something like this:

                    @QListWidgetItem *q1 = new QListWidgetItem("hello", ui->listWidget);@

                    And, according to the documentation, this will add the item to the list too, so it is not required to call the addItem.

                    If you have a sorted list, the above line has an undeterministic behaviour. In this case set the second paramater (parent) of the constructor to 0 and use ui->listWidget->insertItem(...) to insert the new item.

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      endla.ravi
                      wrote on last edited by
                      #10

                      @all,thanQ..

                      I sorted out the problem..

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        vcsala
                        wrote on last edited by
                        #11

                        Maybe it is a good idea to share what was the issue and how you have solved it.

                        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