Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. Qt on BlackBerry and QNX
  4. ShowEvent not working
QtWS25 Last Chance

ShowEvent not working

Scheduled Pinned Locked Moved Qt on BlackBerry and QNX
6 Posts 2 Posters 6.9k Views
  • 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.
  • J Offline
    J Offline
    john_god
    wrote on last edited by
    #1

    I have a very simple and strait forward showEvent(QShowEvent * event) method in a QDialog class that doenst seem to be called when calling exec(). Wonder if this is bug, or something wrong in my code (althoug my code It works on symbian and on desktop) ?

    @protected:
    void showEvent(QShowEvent * event);
    ........

    void SystemEq2_dlg::showEvent(QShowEvent * event)
    {
    ui->listWidget_solutions->clear();
    ui->listWidget_solutions->addItems(this->solutions);
    }
    .....
    dlg2.exec();@

    I've at least other class where showEvent is not being called

    1 Reply Last reply
    0
    • J Offline
      J Offline
      john_god
      wrote on last edited by
      #2

      After all, showEvent() is working, but I dont know why it's not updating the listwidget. I created a pushbutton that does.

      @void SystemEq2_dlg::on_pushButton_solution_clicked()
      {
      ui->listWidget_solutions->clear();
      ui->listWidget_solutions->addItems(this->solutions);
      }@

      It's not a pretty solution because forces the user to an extra button clik, but for now it will have to do untill I figure why showEvent is failling to update the listwidget

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tzander
        wrote on last edited by
        #3

        If your list widget did not get updated from showEvent, the chance is pretty good that there is a race-condition.

        I was thinking of a possible solution to schedule your code to be done very soon after the show event.
        Maybe you want to try using a QTimer::singleshot() to populate it 1ms later.
        You would call a new slot you create on your SystemEq2_dlg class and that slot would have the code you now put in your showEvent() method.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          john_god
          wrote on last edited by
          #4

          Using a singleslot() does the trick

          @void SystemEq2_dlg::showEvent(QShowEvent * event)
          {
          QTimer::singleShot(0, this, SLOT(update()));
          }

          void SystemEq2_dlg::update()
          {
          ui->listWidget_solutions->clear();
          ui->listWidget_solutions->addItems(this->solutions);
          }@

          I'm not sure what is a race condition, but I not using any threads, if its related to that. I also tried

          @void SystemEq2_dlg::update()
          {
          update();
          //or
          emit update();
          }@

          but din't work. I also tried declaring showevent() has a signal and connect it with update but got an error, I guess I cant declare showevent has a signal.
          Overall is not a very nice solution but it works.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tzander
            wrote on last edited by
            #5

            With 'race condition' I meant that there is an ordering issue. You are right I could have chosen better words :)

            What most likely happens is that the showEvent is called just before the widgets inside of it are shown. So when you call your update the widget it is done on ignores it since its still not visible.

            The call to showEvent is just one small part of a lot of stuff that goes on in the single 'show' event.
            Using the singleshot with zero just creates a new event on the event queue to be executed after the show event has completed.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              john_god
              wrote on last edited by
              #6

              Just to add more information on this subject, I notice other widgets, like labels, are updated on the showevent(). Not sure if this behavior could be considered a bug, I always tought that showevent() was suposed to be used in this kind of situation of updating widgets. Anyway it's "fixed" with singleshot()

              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