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. How to access QSqlRelationalModel from function?
Qt 6.11 is out! See what's new in the release blog

How to access QSqlRelationalModel from function?

Scheduled Pinned Locked Moved Solved General and Desktop
32 Posts 2 Posters 16.7k 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.
  • P Panoss

    @mrjj said in How to access QSqlRelationalModel from function?:

    @Panoss said in How to access QSqlRelationalModel from function?:

    Hmm i would have expected it to call
    your constructor but it seems not.
    I thought 'RepairDevices win' calls the constructor.

    @mrjj said in How to access QSqlRelationalModel from function?:

    @Panoss said in How to access QSqlRelationalModel from function?:
    Using a debugger this would be really clear :)
    I did use the debugger but it was not clear at all to me :).

    It still isn't, what must I do?
    I ''l do mainwindow constructor as you suggested and post the result.

    I did the test you suggested me above, I had to change a dot to -> (ui->sn_search_txt to ui.sn_search_txt)

            repairsmodel = new QSqlRelationalTableModel(this);
            QString sn = ui.sn_search_txt->toPlainText();
            repairsmodel ->setFilter("id>76");
            qDebug() << "in refresh_devices_search_tbl";
    

    and got no error.
    The etext is not printed, so the refresh_devices_search_tbl is not called now.

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

    @Panoss said in How to access QSqlRelationalModel from function?:

    refresh_devices_search_tbl

    who calls it ?
    Is it a slot for a button or how should it be called?

    P 1 Reply Last reply
    0
    • mrjjM mrjj

      @Panoss said in How to access QSqlRelationalModel from function?:

      refresh_devices_search_tbl

      who calls it ?
      Is it a slot for a button or how should it be called?

      P Offline
      P Offline
      Panoss
      wrote on last edited by Panoss
      #19

      It 'a a slot for two combo boxes and two textboxes.
      It 's called on textChanged and currentIndexChanged.
      (omg text and index of combos I think do get changed during form's load, e.g when they are mapped to the data mapper.)

      mrjjM 1 Reply Last reply
      0
      • P Panoss

        It 'a a slot for two combo boxes and two textboxes.
        It 's called on textChanged and currentIndexChanged.
        (omg text and index of combos I think do get changed during form's load, e.g when they are mapped to the data mapper.)

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

        @Panoss
        well just check the
        connects and its should be clear why its not called.
        (connect return true / false)

        At some point you will also need to learn to use the debugger and set break points.
        Its THE BEST tool to find out what is happening and where program goes. :)

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Panoss
          wrote on last edited by Panoss
          #21

          I found the guilty!!With the debugger.
          It's a combo box which calls the function at oncurrentIndexChanged event!
          This means that when a combo gets data from a model, the oncurrentIndexChanged event is called!!
          How can I fix this?

          mrjjM 1 Reply Last reply
          0
          • P Panoss

            I found the guilty!!With the debugger.
            It's a combo box which calls the function at oncurrentIndexChanged event!
            This means that when a combo gets data from a model, the oncurrentIndexChanged event is called!!
            How can I fix this?

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

            @Panoss
            I think its by design.
            When it get data, the current
            index is changed so its correct to
            emit the signal.
            Check current index before and after and see.

            Most likely its 100% correct and you might need to use other signal or
            wait until after the data load to set the connect.

            ps. Good work with debugger :)

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Panoss
              wrote on last edited by Panoss
              #23

              Can I do something like this?

              ui.type_search_cbo->cancelEventoncurrentIndexChanged;
              ui.type_search_cbo->setModel(model);
              ui.type_search_cbo->resetEventoncurrentIndexChanged;
              

              (nice code, eh?)

              mrjjM 1 Reply Last reply
              0
              • P Panoss

                Can I do something like this?

                ui.type_search_cbo->cancelEventoncurrentIndexChanged;
                ui.type_search_cbo->setModel(model);
                ui.type_search_cbo->resetEventoncurrentIndexChanged;
                

                (nice code, eh?)

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

                @Panoss

                well i would prefer if you could just wait to connect the slots
                so its ok it says index changed.

                There is
                http://doc.qt.io/qt-5/qobject.html#blockSignals

                but again, you are fixing a symptom so it not the best.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  Panoss
                  wrote on last edited by
                  #25

                  Yes, it works with block signals.
                  So, this is not the correct remedy?

                  How could I wait to connect the slots?
                  I don't want just to fix the symptom, I want to do it properly.

                  mrjjM 1 Reply Last reply
                  0
                  • P Panoss

                    Yes, it works with block signals.
                    So, this is not the correct remedy?

                    How could I wait to connect the slots?
                    I don't want just to fix the symptom, I want to do it properly.

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

                    @Panoss
                    well where do you hook up the oncurrentIndexChanged signal?

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      Panoss
                      wrote on last edited by Panoss
                      #27

                      It's a slot for a combo:

                      void RepairDevices::on_type_search_cbo_currentIndexChanged(int index)
                      {
                          refresh_devices_search_tbl(); 
                      }
                      
                      mrjjM 1 Reply Last reply
                      0
                      • P Panoss

                        It's a slot for a combo:

                        void RepairDevices::on_type_search_cbo_currentIndexChanged(int index)
                        {
                            refresh_devices_search_tbl(); 
                        }
                        
                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #28

                        @Panoss said in How to access QSqlRelationalModel from function?:

                        Ah you are using the auto connect feature?
                        you do not have connect( xxxx) , correct ?

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          Panoss
                          wrote on last edited by Panoss
                          #29

                          No, I don't even know what autoconnect is.
                          I have no connect( xxxx) for this function.
                          (unless you 're meaning that this way, it 's autoconnected)

                          mrjjM 1 Reply Last reply
                          0
                          • P Panoss

                            No, I don't even know what autoconnect is.
                            I have no connect( xxxx) for this function.
                            (unless you 're meaning that this way, it 's autoconnected)

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

                            @Panoss

                            well it means it will hook it up if names matches.
                            QMetaObject::connectSlotsByName(MainWindow);
                            ( in setupUI)

                            just use blockSignals then. :)

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              Panoss
                              wrote on last edited by
                              #31

                              Thank you very much mrjj, you helped me A LOT!

                              mrjjM 1 Reply Last reply
                              1
                              • P Panoss

                                Thank you very much mrjj, you helped me A LOT!

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

                                @Panoss
                                Np.
                                Thats why i lurk around here :)

                                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