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. [SOLVED] how to get the QmodelIndex to a QString?
Qt 6.11 is out! See what's new in the release blog

[SOLVED] how to get the QmodelIndex to a QString?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 8.0k 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.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #1

    i am trying to get the current index of the listwidget but i am having problems. when i type
    @
    if (ui->userListWidget->currentIndex() == 0)@

    i get an error: no match for 'operator==' in 'QAbstractItemView::currentIndex() const() == 0'. candidates are: bool QModelIndex::operator==(const QModelIndex&) const

    when i type
    @
    QString temp = ui->userListWidget->currentIndex(); @

    to get the string, i get the error: conversion from 'QModelIndex' to non-scalar type 'QString' requested.

    how to get the QmodelIndex to a QString?

    [edit, please add @ code tags to make your post easier to read, Eddy]

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      "The docs":http://developer.qt.nokia.com/doc/qt-4.8/qabstractitemview.html#currentIndex say that currentIndex returns a QModelIndex

      So you could use it's "isValid member":http://developer.qt.nokia.com/doc/qt-4.8/qmodelindex.html#isValid

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kalster
        wrote on last edited by
        #3

        i am using...
        @bool QModelIndex::isValid () const@

        i am getting the error...
        no matching function for call to 'QTextEdit::append(bool)'

        i am trying to print the results to the textEdit

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          Please show us the relevant code. We don't have a cristal ball to see where that textEdit comes from ;)

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kalster
            wrote on last edited by
            #5

            ok Eddy. here is the code. thank you.

            @ QModelIndex temp = ui->userListWidget->currentIndex();
            textEdit[0]->append(temp.isValid());@

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              I don't quiet understand what you want to achieve generally speaking. But if it is your goal to show the row number of the selected item you could use "currentRow":http://developer.qt.nokia.com/doc/qt-4.8/qlistwidget.html#currentRow-prop.

              This gives you an int, which you can use in your textEdit.
              Is that what you want?

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                What is "the string"? What do you want to append to your text edit? If you have a snippet of code that does not work, then please tell your fellow forumistas what you want to achieve. It's hard to guess this from broken code. I do have a guess and I'm pretty sure I now what you want to do, but I want to hear that from you.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kalster
                  wrote on last edited by
                  #8

                  lets say there are three items in the listwidget. when a user clicks the second item, i want to get the index from it. so the code would return number 2. the listwidget.currentindex does return it but in a modelindex. i need the number to be in a string so that i can work with it.

                  after reading Eddy's last post, i tested the currentRow and it is just what i was looking for. i marked this topic as solved.

                  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