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. Crashing with GUI?

Crashing with GUI?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.0k 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.
  • C Offline
    C Offline
    CroCo
    wrote on last edited by
    #1

    I want to design a trivial counter GUI. Once the user presses the counter button, the counter starts counting.

    @void Window::BCounterClicked() const
    {
    static int COUNTER(0);
    do {
    QString count_str = QString::number(COUNTER);
    label->setText(count_str);
    ++COUNTER;
    }while(true);
    } @

    Once I press the button, the app crashes. Why this occurs?
    Second question, I want to use pause system. Which method should I use?

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

      with while(true) you are entering an infinite loop; that's definitely not something you want to happen in a click-signal; i.e. you'll never leave this loop

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        label is pointer variable. Hope you have initialized it. If you have not initialized it will crash. Also you are constructing too many string variable in infinitely. This could the reason for crash.

        Regarding the puase, I suggest you make this function as slot. Start the timer at some interval and connect to this slot. Slot should be increment counter ans set label. In this case you don't to have to worry about the infinite loop and pause etc.

        Also you have defined the method as const. It means that is ready only method. It is not suppose to change the value of any member variable.

        Alternatively you can use the QLCD class itself which gives the counter functionality.

        My suggestion is that you can make the second question as separate question. You may get a other answer as ell.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • C Offline
          C Offline
          CroCo
          wrote on last edited by
          #4

          @JazzKatua, going in an infinite loop doesn't justify the crashing problem.

          @dheerendra, Yes I did initialized the label. Also, this function is a private slot function. Would you please elaborate about "Slot should be increment counter and set label". What do you mean exactly? With const function, it works if there is no do-while loop. It means that there is no problem with setting it as const.

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            Here is the code snippet

            @QTimer timer;
            timer.setIntervaal(10Sec) - (Imean to say give appropriate interval)
            timer.start()
            connect(&timer,SIGNAL(timeout()),this,SLOT(counterClicked()) )@

            @void Window::counterClicked() const
            {
            static int COUNTER(0);
            QString count_str = QString::number(COUNTER);
            label->setText(count_str);
            ++COUNTER;
            }
            @
            Change the timer interval accordingly. This will give the same functionality what you are asking. Hope this solves your problem.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0
            • C Offline
              C Offline
              CroCo
              wrote on last edited by
              #6

              @Dheerendra, thanks for being helpful

              1 Reply Last reply
              0
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by
                #7

                It is my pleasure. If solution has helped you, can put your request into solved state ?

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

                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