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. Multiple AutoCompleters for the same LineEdit box

Multiple AutoCompleters for the same LineEdit box

Scheduled Pinned Locked Moved Solved General and Desktop
26 Posts 3 Posters 6.2k Views 2 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.
  • mrjjM mrjj

    Hi
    where is your setupUI() ?

    C Offline
    C Offline
    Core2
    wrote on last edited by
    #6

    @mrjj

    The animalsearch ui is launched when a button is clicked on the parent ui. Does that answer the question? I'm not a seasoned Qt user so I may have not understood your question. Thanks for your time.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #7

      Hi
      sorry if not clear.
      Normally when using UI files, there is a call to a function that creates the objects.
      MainWindow::MainWindow(QWidget* parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow) {
      ui->setupUi(this); <<<< --- std.

      I could not see in your code so i did wonder. but if it runs it must be there :)

      C 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        sorry if not clear.
        Normally when using UI files, there is a call to a function that creates the objects.
        MainWindow::MainWindow(QWidget* parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow) {
        ui->setupUi(this); <<<< --- std.

        I could not see in your code so i did wonder. but if it runs it must be there :)

        C Offline
        C Offline
        Core2
        wrote on last edited by
        #8

        @mrjj
        Ok yeah i see that in the mainview.cpp which launches the animalsearch ui. It's exactly as you posted.

        mrjjM 1 Reply Last reply
        0
        • C Core2

          @mrjj
          Ok yeah i see that in the mainview.cpp which launches the animalsearch ui. It's exactly as you posted.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #9

          @Core2
          Ok, but i assume you have the same for AnimalSearch or else anything you have in the UI files
          will be dangling pointers.

          You call setupUI manually from mainwindow or something like that ?

          Can you show how you init AnimalSearch ?
          if you never call setup, the line ui->cmbFilter->xxx would crash
          so since it seems something else, i guess its ok, just not standard way?

          C 1 Reply Last reply
          0
          • mrjjM mrjj

            @Core2
            Ok, but i assume you have the same for AnimalSearch or else anything you have in the UI files
            will be dangling pointers.

            You call setupUI manually from mainwindow or something like that ?

            Can you show how you init AnimalSearch ?
            if you never call setup, the line ui->cmbFilter->xxx would crash
            so since it seems something else, i guess its ok, just not standard way?

            C Offline
            C Offline
            Core2
            wrote on last edited by Core2
            #10

            @mrjj

            from mainview.cpp

            //Needs better commenting.
            void MainView::on_btnAnimalSearch_clicked()
            {
                AnimalSearch animalsearch;
                animalsearch.setModal(true);
                connect(&animalsearch, SIGNAL(sendData(QString)), this, SLOT(printData(QString)));
                animalsearch.exec();
            }
            
            mrjjM 1 Reply Last reply
            0
            • C Core2

              @mrjj

              from mainview.cpp

              //Needs better commenting.
              void MainView::on_btnAnimalSearch_clicked()
              {
                  AnimalSearch animalsearch;
                  animalsearch.setModal(true);
                  connect(&animalsearch, SIGNAL(sendData(QString)), this, SLOT(printData(QString)));
                  animalsearch.exec();
              }
              
              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #11

              @Core2
              ok. odd. but dialog works and the widgets in the UI are shown so
              that part does work?
              I mean, there is no issues with
              ui->cmbFilter->addItems(animals); ?
              That would really crash if dangling pointer.

              C 1 Reply Last reply
              0
              • mrjjM mrjj

                @Core2
                ok. odd. but dialog works and the widgets in the UI are shown so
                that part does work?
                I mean, there is no issues with
                ui->cmbFilter->addItems(animals); ?
                That would really crash if dangling pointer.

                C Offline
                C Offline
                Core2
                wrote on last edited by
                #12

                @mrjj

                yeah that part works and has been for some time. now that i introduced multiple Qcompleters and trying to assign a Qcompleter depending on cmbFilter state is when things started failing. As you can see from the example code above I assign a default of TurtleQcompleter, and then in the section of code:

                void AnimalSearch::on_cmbFilter_currentIndexChanged()
                

                runs when the animalsearch ui is started, even though I don't change the cmbFilter, and I try for a test to set the Qcompleter to Rabbit Qcompleter from the earlier assignment of TurtleQcompleter.

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #13

                  Hi
                  yes it will fire such signal when current item/index is set.
                  Also when done in code as doc states
                  http://doc.qt.io/qt-5/qcombobox.html#currentIndexChanged
                  So that is pretty normal.

                  C 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    Hi
                    yes it will fire such signal when current item/index is set.
                    Also when done in code as doc states
                    http://doc.qt.io/qt-5/qcombobox.html#currentIndexChanged
                    So that is pretty normal.

                    C Offline
                    C Offline
                    Core2
                    wrote on last edited by
                    #14

                    @mrjj

                    Ok good to know. I will remove my line where I assign a default Qcompleter, and allow this section of code to make the first assignment.

                    Now i just have to figure out after I make the Qcompleters why i can't assign a different Qcompleter from elsewhere in the code.

                    Thanks again for your time.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #15

                      Can you show the backtrace from your crash ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      C 1 Reply Last reply
                      1
                      • SGaistS SGaist

                        Can you show the backtrace from your crash ?

                        C Offline
                        C Offline
                        Core2
                        wrote on last edited by
                        #16

                        @SGaist

                        backtrace? I don't know what that is.

                        C 1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #17

                          It's the list of functions called shown by the debugger when the application crashes.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          C 1 Reply Last reply
                          0
                          • mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #18

                            Hi
                            What you mean by
                            "why i can't assign a different Qcompleter from elsewhere in the code" ?
                            In what why does it not work ?

                            C 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              It's the list of functions called shown by the debugger when the application crashes.

                              C Offline
                              C Offline
                              Core2
                              wrote on last edited by Core2
                              #19

                              @SGaist

                              I think by watching this video by VoidRealms I will be able to gather this info.
                              https://www.youtube.com/watch?v=B7UsWtyhXh4

                              1 Reply Last reply
                              1
                              • mrjjM mrjj

                                Hi
                                What you mean by
                                "why i can't assign a different Qcompleter from elsewhere in the code" ?
                                In what why does it not work ?

                                C Offline
                                C Offline
                                Core2
                                wrote on last edited by
                                #20

                                @mrjj

                                I mean that in the animalsearch ui(new Ui::AnimalSearch) I create the Qcompleters from data i collect from sql into a model that i parse to QstringLists, then in a cmbFilter slot I assign the Qcompleter to the lineBy box.

                                mrjjM 1 Reply Last reply
                                0
                                • C Core2

                                  @mrjj

                                  I mean that in the animalsearch ui(new Ui::AnimalSearch) I create the Qcompleters from data i collect from sql into a model that i parse to QstringLists, then in a cmbFilter slot I assign the Qcompleter to the lineBy box.

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #21

                                  @Core2
                                  Ok. that should just work.
                                  I tried the Qt completer sample and there seems to be no issues switching completer.

                                  C 1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    @Core2
                                    Ok. that should just work.
                                    I tried the Qt completer sample and there seems to be no issues switching completer.

                                    C Offline
                                    C Offline
                                    Core2
                                    wrote on last edited by
                                    #22

                                    @mrjj

                                    Interesting. I may set up a test project where i set up a basic program to do this one thing with a cmbFilter, and a LineEdit. Until then I think I go the debugger working and am getting good info. I'm about to respond to SGaist.

                                    mrjjM 1 Reply Last reply
                                    1
                                    • C Core2

                                      @mrjj

                                      Interesting. I may set up a test project where i set up a basic program to do this one thing with a cmbFilter, and a LineEdit. Until then I think I go the debugger working and am getting good info. I'm about to respond to SGaist.

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #23

                                      @Core2
                                      Ok. good plan. The call stack will show what happened up till the crash.
                                      alt text

                                      1 Reply Last reply
                                      0
                                      • C Core2

                                        @SGaist

                                        backtrace? I don't know what that is.

                                        C Offline
                                        C Offline
                                        Core2
                                        wrote on last edited by
                                        #24

                                        @Core2

                                        In the issues window: "c:\blahblahblah\qt\qtbase\src\corelib\tools\qscopedpointer.h:140: error: Debugger encountered an exception: Exception at 0x7747379a, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance)

                                        In the Debugger Window: There is 76 Levels, and there is a yellow arrow pointing to the level 11, AnimalSearch::on_cmbFilter_currentIndexChanged.
                                        The file column of that row contains this animalsearch.cpp
                                        The line row contains 300, which is the line just after the line ui->lineBy->setCompleter(RabbitCompleter);

                                        Looking at the top right window after i click on the level 11, I can see what variables are in memory and what the value and types are (Too freaking cool!)

                                        Is the information i listed above the backtrace?

                                        1 Reply Last reply
                                        0
                                        • mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #25

                                          Hi
                                          I would check the values of all UI widgets (if non null)
                                          and i would also
                                          change so .h says
                                          QCompleter *TurtleCompleter=0;
                                          QCompleter *RabbitCompleter=0;
                                          QCompleter *DogCompleter=0;
                                          QCompleter *CatCompleter=0;

                                          so im sure they are allocated when i reach crash point ( as in not null)

                                          The error code: 0xc0000005: + 0x0, suggests a null pointer.

                                          C 1 Reply Last reply
                                          2

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved