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

Search between labels

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 863 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
    mohamaddanesh44
    wrote on last edited by
    #1

    hi
    i have some QLabels,
    i wanna create a field which when i type in it and press "enter" it goes through labels and prints the search results in a new frame. something like a very simple search engine.

    i really need that.

    any help would be appreciated.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      So what's the question? :)

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qurban_ali36
        wrote on last edited by
        #3

        To implement this task QRegExp class is your friend.
        put all the labels in a QList and loop through this list, this will match the text in the search field with each label's text. If the text matches, append the matched label to another QList. Finally put all the matched label to a separate QFrame.
        here is "for loop"
        @
        QRegExp rx("");
        // call this function when user presses enter key and
        //pass the text in the search field
        void searchLabels(QString name) {
        //list contains all the labels
        for (int i = 0; i < list.length(); i++) {
        //searchField is object of QLineEdit
        rx.setPattern(name);
        if (rx.indexIn(list[i]->text()) != -1) {
        // appned the label at list[i] to new QList
        // or you can append new label to the
        // list (depends upon your needs)
        }//if
        }//for
        }//searchLabels
        @

        I am not a C++ developer. if you find syntax problems, sorry for that.

        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