Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QlistView is empty or not?

QlistView is empty or not?

Scheduled Pinned Locked Moved Qt Creator and other tools
12 Posts 3 Posters 5.8k Views
  • 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.
  • F Offline
    F Offline
    freecamellia
    wrote on last edited by
    #1

    Hi,
    Is there a method that check if a QlistView is empty or not?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      @
      if (theView->model()->rowCount() == 0) {
      //do your thing
      }
      @
      Or something along those lines...

      1 Reply Last reply
      0
      • S Offline
        S Offline
        StephanWoebbeking
        wrote on last edited by
        #3

        Hope it's ok to reply to this thread, even it's been created in the jura ära already? ;)

        I have exactly the same question, even have the same solution, but the point is, how can find someone find out, if not the MODEL is empty, but the QListView is empty, means, it does not have a model yet attached? In my case I have a certain use case where there were no items found yet to add (on purpose), so even the model wasn't created and added to the QListView item. So view->model()->rowCount() produces a segmentation fault - which is perfectly ok, but how can I check before this request, if the model does exist already? view->model() == 0 or something? My trials were rejected by the compiler so far.

        Cheers,
        Stephan

        1 Reply Last reply
        0
        • S Offline
          S Offline
          StephanWoebbeking
          wrote on last edited by
          #4

          Hope it's ok to reply to this thread, even it's been created in the jura ära already? ;)

          I have exactly the same question, even have the same solution, but the point is, how can find someone find out, if not the MODEL is empty, but the QListView is empty, means, it does not have a model yet attached? In my case I have a certain use case where there were no items found yet to add (on purpose), so even the model wasn't created and added to the QListView item. So view->model()->rowCount() produces a segmentation fault - which is perfectly ok, but how can I check before this request, if the model does exist already? view->model() == 0 or something? My trials were rejected by the compiler so far.

          Cheers,
          Stephan

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Check if calling model() returns 0 on your view.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Check if calling model() returns 0 on your view.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                StephanWoebbeking
                wrote on last edited by
                #7

                Ok, that works, why did I not get to that idea??? ;)

                Would you use "0" or rather "NULL"?

                Stephan

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  StephanWoebbeking
                  wrote on last edited by
                  #8

                  Ok, that works, why did I not get to that idea??? ;)

                  Would you use "0" or rather "NULL"?

                  Stephan

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    0 in c++/98, nullptr in c++/11. NULL is C.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      0 in c++/98, nullptr in c++/11. NULL is C.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        StephanWoebbeking
                        wrote on last edited by
                        #11

                        Great, thanks!

                        Stephan

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          StephanWoebbeking
                          wrote on last edited by
                          #12

                          Great, thanks!

                          Stephan

                          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