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] qcombobox and clear()
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] qcombobox and clear()

Scheduled Pinned Locked Moved General and Desktop
27 Posts 10 Posters 38.7k 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #5

    What does your debugger say? You can break at the assertpoint to get a stack trace, or force Qt to crash on a failed assert (which would also get a stack trace). Follow that trace to the first point in your own code, and you'll be on to where the problem came from.

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xeroblast
      wrote on last edited by
      #6

      this is what my debugger says :

      Debug...
      Reading symbols from /directory/bin/icons...done.
      (gdb)
      (gdb) (gdb) (gdb) (gdb) Starting program: /directory/bin/icons
      [Thread debugging using libthread_db enabled]
      [New Thread 0x7fffe2e4c700 (LWP 27112)]
      [Thread 0x7fffe2e4c700 (LWP 27112) exited]
      Program received signal SIGABRT, Aborted.
      0x00007ffff489da75 in raise () from /lib/libc.so.6
      (gdb)
      QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed: No such file or directory
      QFileSystemWatcher: failed to add paths: /home/my_profile/.config/ibus/bus
      Bus::open: Can not get ibus-daemon's address.
      IBusInputContext::createInputContext: no connection to ibus-daemon
      Object::connect: (sender name: 'AddItemPurchaseOrder')
      Object::connect: (receiver name: 'CreatePurchaseOrder')
      ASSERT failure in QVector<T>::operator[]: "index out of range", file /usr/include/qt4/QtCore/qvector.h, line 346

      then it crash.. need to force quit...

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

        No, you need to get a stack trace. Gdb supplies the bt command for that.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xeroblast
          wrote on last edited by
          #8

          how to get the stacktrace? i dont know how.. im using QDevelop & QTDesigner..

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xeroblast
            wrote on last edited by
            #9

            i even try only this :

            @
            void AddItemPurchaseOrderImpl::changeCategory(QString val)
            {
            if (val == "New Category") {
            dropdownCategory->setEditable(true);
            } else {
            dropdownProduct->clear();
            }
            }
            @

            and still gives me an error.. clearing-up the qcombobox is giving an error..

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #10

              How do you fill the combo box?

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • X Offline
                X Offline
                xeroblast
                wrote on last edited by
                #11

                this is how i fill it :
                dropdownProduct->addItem("Value");

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

                  [quote author="xeroblast" date="1294126914"]how to get the stacktrace? i dont know how.. im using QDevelop & QTDesigner..[/quote]

                  I suggested two ways earlier. Anyhow, this is one (rather brute force) way to do it. When an assert is triggered, it will force a hard crash that you can catch in your debugger.

                  @
                  //in main.cpp
                  void crashingMessageHandler(QtMsgType type, const char *msg)
                  {
                  switch (type) {
                  case QtDebugMsg:
                  fprintf(stderr, "Debug: %s\n", msg);
                  break;
                  case QtWarningMsg:
                  fprintf(stderr, "Warning: %s\n", msg);
                  break;
                  case QtCriticalMsg:
                  fprintf(stderr, "Critical: %s\n", msg);
                  break;
                  case QtFatalMsg:
                  fprintf(stderr, "Fatal: %s\n", msg);
                  __asm("int3");
                  abort();
                  }
                  }

                  int main(int argc, char ** argv)
                  {
                  qInstallMsgHandler(crashingMessageHandler);
                  ...// rest of your main function
                  }
                  @

                  It is a blunt axe, but it works (ok, depending on your compiler or platform I guess).

                  After inserting the code above, make sure that you compile in debug mode, not in release mode. Then, in QtCreator, press F5 to start your debug run. Your program will start (though it will take more time!). Trigger the problem, and you will be able to see a stack trace: the table with the Level, Function, File and Line headers. Find the first file that contains code that you wrote, and you will see the function name and line number that triggered the problem.

                  1 Reply Last reply
                  0
                  • X Offline
                    X Offline
                    xeroblast
                    wrote on last edited by
                    #13

                    this is the result that the debugger catch using the above code..

                    Warning: Object::connect: (sender name: 'AddItemPurchaseOrder')
                    Warning: Object::connect: (receiver name: 'CreatePurchaseOrder')
                    Fatal: ASSERT failure in QVector<T>::operator[]: "index out of range", file /usr/include/qt4/QtCore/qvector.h, line 346
                    Scope for 20:
                    Symbol type is a variable with complex or multiple locations (DWARF2), length 4.
                    Symbol msg is a variable with complex or multiple locations (DWARF2), length 8.

                    i tried everything as simple like inputting manual data in the qcombobox. and if there is already item/s in the combobox then an error appear... if i dont put initial item/s, it will only run correctly in the first, on second select, the error appears again..

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

                      No, this is not the backtrace.

                      You should really get the list of function calls that led to your crash.

                      1 Reply Last reply
                      0
                      • X Offline
                        X Offline
                        xeroblast
                        wrote on last edited by
                        #15

                        that's what appears in the debugger.. btw, im using ubuntu..

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

                          If you are running your app in the debugger from the commandline, issue the bt command to gdb after the crash. From QtCreator, the backtrace should pop up automatically if a crash happens in debug mode.

                          1 Reply Last reply
                          0
                          • X Offline
                            X Offline
                            xeroblast
                            wrote on last edited by
                            #17

                            im sorry but there is no popup.. im using QDevelop & QtDesigner in ubuntu..

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

                              QDevelop is not the same as QtCreator. And it is not a popup, it is part of the debug mode in that program.

                              Try this, on the commandline:

                              gdb path/to/your/executable

                              let your application crash, and then, still on the gdb prompt:

                              bt

                              That should give you your stack/back trace.

                              1 Reply Last reply
                              0
                              • X Offline
                                X Offline
                                xeroblast
                                wrote on last edited by
                                #19

                                im sorry but the gdb /path/to/exe is not working. no program running..

                                Reading symbols from /home/edril/Documents/Desktop Projects/EquiApps/bin/EquiApps...done.
                                (gdb)

                                cursor is always blinking..

                                1 Reply Last reply
                                0
                                • X Offline
                                  X Offline
                                  xeroblast
                                  wrote on last edited by
                                  #20

                                  i found the problem...

                                  i disconnect first the signal in the dropdownProduct before using the clear().

                                  @
                                  void AddItemPurchaseOrderImpl::changeCategory(QString val)
                                  {
                                  disconnect(dropdownProduct, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeProduct(QString)));
                                  bool firstrun = true;
                                  dropdownProduct->clear();
                                  if (val == "New Category") {
                                  dropdownCategory->setEditable(true);
                                  } else {
                                  dropdownCategory->setEditable(false);
                                  QSqlDatabase db = dbaseAddItemPO.dbConnect();
                                  QVector<QMap<QString, QString> > products;
                                  if (val == "Uncategorized") {
                                  products = dbaseAddItemPO.getData("SELECT id, product_name FROM products WHERE category_id IS NULL");
                                  } else {
                                  QVector<QMap<QString, QString> > category = dbaseAddItemPO.getData("SELECT id FROM category WHERE category_name='" + val + "'");
                                  products = dbaseAddItemPO.getData("SELECT id, product_name FROM products WHERE category_id='" + category[0].value("id") + "'");
                                  }
                                  if (products.size() != 0) {
                                  for (int i=0; i < products.size(); i++) {
                                  dropdownProduct->addItem(products[i].value("product_name"));
                                  if (firstrun) {
                                  QVector<QMap<QString, QString> > brands = dbaseAddItemPO.getData("SELECT brand_name FROM product_details WHERE products_id='" + products[i].value("id") + "'");
                                  if (brands.size() != 0) {
                                  for (int j=0; j < brands.size(); j++) {
                                  dropdownBrand->addItem(brands[i].value("brand_name"));
                                  }
                                  }
                                  firstrun = false;
                                  }
                                  }
                                  }
                                  dropdownProduct->addItem("New Product");
                                  db.close();
                                  }
                                  dbaseAddItemPO.dbRemove();
                                  connect(dropdownProduct, SIGNAL(currentIndexChanged(QString)), this, SLOT(changeProduct(QString)));
                                  }
                                  @

                                  and reconnect it at the end.
                                  thanx to all your replies..

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

                                    Glad that you found the problem, but I would really like to advice you to learn some basic debugging skills. Problems of finding why an application crashes are something every developer will have to diagnose, sooner or later. Getting and reading & understanding a backtrace is a basic tool to fix those.

                                    1 Reply Last reply
                                    0
                                    • F fcrochik

                                      I would venture a guess that the error is not on these lines of code.

                                      Most likely is something that you doing somewhere else while processing signals that get triggered by adding/removing items. For example you may have code to process when the selected item changes on the combo - clearing the combo and adding new items will probably trigger that.

                                      rohit713R Offline
                                      rohit713R Offline
                                      rohit713
                                      wrote on last edited by
                                      #22

                                      @fcrochik said in [SOLVED] qcombobox and clear():

                                      I would venture a guess that the error is not on these lines of code.

                                      Most likely is something that you doing somewhere else while processing signals that get triggered by adding/removing items. For example you may have code to process when the selected item changes on the combo - clearing the combo and adding new items will probably trigger that.

                                      Yes you are right. I also facing the same problem.

                                      mrjjM 1 Reply Last reply
                                      0
                                      • rohit713R rohit713

                                        @fcrochik said in [SOLVED] qcombobox and clear():

                                        I would venture a guess that the error is not on these lines of code.

                                        Most likely is something that you doing somewhere else while processing signals that get triggered by adding/removing items. For example you may have code to process when the selected item changes on the combo - clearing the combo and adding new items will probably trigger that.

                                        Yes you are right. I also facing the same problem.

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

                                        @rohit713
                                        The debugger is your friend in that case.

                                        rohit713R 1 Reply Last reply
                                        3
                                        • mrjjM mrjj

                                          @rohit713
                                          The debugger is your friend in that case.

                                          rohit713R Offline
                                          rohit713R Offline
                                          rohit713
                                          wrote on last edited by
                                          #24

                                          @mrjj
                                          Yes I disconnect the signal and after clearing the combobox I connect the signal again, now problem is solved by doing so.

                                          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