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. QLineEdit combined with QStackedWidget, crash

QLineEdit combined with QStackedWidget, crash

Scheduled Pinned Locked Moved Solved General and Desktop
20 Posts 5 Posters 1.2k 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.
  • WenchiW Offline
    WenchiW Offline
    Wenchi
    wrote on last edited by Wenchi
    #1

    Hello everyone, I found a bug when I used QLineEdit and QStackedWidget at the same time.
    I have three independent controls: QLineEdit ,QStackedWidget ,QPushButton.
    0cfb010f-007c-4525-98d8-7018316b223e-企业微信截图_16659984944558.png
    I combined signal QLineEdit::textChanged and a slot. In the slot, I changed the CurrentIndex of QStackedWidget by using setCurrentIndex().

    void MainWindow::lineEdit_textChanged(const QString &arg1)
    {
        qDebug()<<"on_lineEdit_textChanged"<<arg1;
        //ui->lineEdit->blockSignals(true);
        ui->stackedWidget->setCurrentIndex(1);
        //ui->lineEdit->blockSignals(false);
    }
    
    

    Then I input something in the QLineEdit under the Chinese input method while I didn't press the Enter Key at last to finish my input.
    dc527046-8a8c-44f9-b636-57cc28f3b0f4-image.png
    At this status, I clicked the QPushButton on the right to make the QLineEdit lose focus.
    Then this program crashed.
    2d1c0cd9-f77b-4d05-9fc0-24be8edc5a38-企业微信截图_16659918028280.png

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • WenchiW Wenchi

      @JonB
      First allow me to explain the "Chinese input method":
      When I input "test":
      68678bb1-869c-400d-a029-84dffe45e3e9-image.png
      Then I can click "1"(or "2" or "3"...) or press "Enter" and the input is finished and this status won't cause crash:
      11ce04b2-e558-41bd-896d-35a9ea96564a-image.png
      If I click somewhere else, the input is not finished and this status can cause crash:
      aed5348d-526b-49f6-89be-464bb42eae1f-image.png
      To fix this problem, I add the code "blockSignals":

      void MainWindow::lineEdit_textChanged(const QString &arg1)
      {
          qDebug()<<"on_lineEdit_textChanged"<<arg1;
          ui->lineEdit->blockSignals(true);
          ui->stackedWidget->setCurrentIndex(1);
          ui->lineEdit->blockSignals(false);
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #16

      @Wenchi
      OK, now I know (a bit) about how "Chinese input" works! But I suspect this itself is not the issue, assuming @Bonnie is reproducing the issue.

      I am not a great fan of blockSignals(), one is never sure what the side-effects ignoring signals might be. Given that I suggested that QLineEdit might not having like focus changed while inside textChanged() signal, what about the QTimer alternative I suggested instead of blocking signals:

      QTimer::singleShot(0, [this]() { ui->stackedWidget->setCurrentIndex(1); });
      
      WenchiW 1 Reply Last reply
      2
      • WenchiW Wenchi

        Hello everyone, I found a bug when I used QLineEdit and QStackedWidget at the same time.
        I have three independent controls: QLineEdit ,QStackedWidget ,QPushButton.
        0cfb010f-007c-4525-98d8-7018316b223e-企业微信截图_16659984944558.png
        I combined signal QLineEdit::textChanged and a slot. In the slot, I changed the CurrentIndex of QStackedWidget by using setCurrentIndex().

        void MainWindow::lineEdit_textChanged(const QString &arg1)
        {
            qDebug()<<"on_lineEdit_textChanged"<<arg1;
            //ui->lineEdit->blockSignals(true);
            ui->stackedWidget->setCurrentIndex(1);
            //ui->lineEdit->blockSignals(false);
        }
        
        

        Then I input something in the QLineEdit under the Chinese input method while I didn't press the Enter Key at last to finish my input.
        dc527046-8a8c-44f9-b636-57cc28f3b0f4-image.png
        At this status, I clicked the QPushButton on the right to make the QLineEdit lose focus.
        Then this program crashed.
        2d1c0cd9-f77b-4d05-9fc0-24be8edc5a38-企业微信截图_16659918028280.png

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @Wenchi If your app is crashing then please first run it through debugger and post stack trace here.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        WenchiW 1 Reply Last reply
        1
        • WenchiW Wenchi

          Hello everyone, I found a bug when I used QLineEdit and QStackedWidget at the same time.
          I have three independent controls: QLineEdit ,QStackedWidget ,QPushButton.
          0cfb010f-007c-4525-98d8-7018316b223e-企业微信截图_16659984944558.png
          I combined signal QLineEdit::textChanged and a slot. In the slot, I changed the CurrentIndex of QStackedWidget by using setCurrentIndex().

          void MainWindow::lineEdit_textChanged(const QString &arg1)
          {
              qDebug()<<"on_lineEdit_textChanged"<<arg1;
              //ui->lineEdit->blockSignals(true);
              ui->stackedWidget->setCurrentIndex(1);
              //ui->lineEdit->blockSignals(false);
          }
          
          

          Then I input something in the QLineEdit under the Chinese input method while I didn't press the Enter Key at last to finish my input.
          dc527046-8a8c-44f9-b636-57cc28f3b0f4-image.png
          At this status, I clicked the QPushButton on the right to make the QLineEdit lose focus.
          Then this program crashed.
          2d1c0cd9-f77b-4d05-9fc0-24be8edc5a38-企业微信截图_16659918028280.png

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #3

          @Wenchi your crash is totally unrelated to QStackWidget.

          inside "on_lineEdit_textChanged" you're changing the text of the lineEdit, retriggering the signal -> repeatedly calling the on_lineEdit_textChanged slot and eventually running out of stack space


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          WenchiW 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Wenchi If your app is crashing then please first run it through debugger and post stack trace here.

            WenchiW Offline
            WenchiW Offline
            Wenchi
            wrote on last edited by
            #4

            @jsulm this is just a demo, the code is very simple, just a QLineEdit, a QStackedWidget and a QPushButton. And it crashed necessarily in running mode, while it didn't crash in debugging mode. I think this is a Qt's bug since the code is too simple and it crashed necessarily.

            jsulmJ 1 Reply Last reply
            0
            • J.HilkJ J.Hilk

              @Wenchi your crash is totally unrelated to QStackWidget.

              inside "on_lineEdit_textChanged" you're changing the text of the lineEdit, retriggering the signal -> repeatedly calling the on_lineEdit_textChanged slot and eventually running out of stack space

              WenchiW Offline
              WenchiW Offline
              Wenchi
              wrote on last edited by
              #5

              @J-Hilk Look the code, I am not changing the text of the linEdit. I just changed the stackedWidget's currentIndex. If I comment this line, it won't crash:

              ui->stackedWidget->setCurrentIndex(1);
              
              1 Reply Last reply
              0
              • WenchiW Wenchi

                @jsulm this is just a demo, the code is very simple, just a QLineEdit, a QStackedWidget and a QPushButton. And it crashed necessarily in running mode, while it didn't crash in debugging mode. I think this is a Qt's bug since the code is too simple and it crashed necessarily.

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @Wenchi said in QLineEdit combined with QStackedWidget, crash:

                I think this is a Qt's bug since the code is too simple and it crashed necessarily

                Before claiming there is a bug in Qt you should find out where and why it crashes.
                Please take a look at the output of your app: there are many many on_lineEdit_textChanged calls - what does it do (post its code)? I guess @J-Hilk is right and you have an endless loop...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                WenchiW 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @Wenchi said in QLineEdit combined with QStackedWidget, crash:

                  I think this is a Qt's bug since the code is too simple and it crashed necessarily

                  Before claiming there is a bug in Qt you should find out where and why it crashes.
                  Please take a look at the output of your app: there are many many on_lineEdit_textChanged calls - what does it do (post its code)? I guess @J-Hilk is right and you have an endless loop...

                  WenchiW Offline
                  WenchiW Offline
                  Wenchi
                  wrote on last edited by Wenchi
                  #7

                  @jsulm Here I post the whole code. As you can see I didn't change the lineEdit's text, I still don't understand why there're so many lineEdit_textChanged calls. I can only tell that changing the stackedWidget's current index is the reason which causes so many lineEdit_textChanged calls.

                  #include "mainwindow.h"
                  #include "./ui_mainwindow.h"
                  
                  #include <QDebug>
                  
                  MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent)
                    , ui(new Ui::MainWindow)
                  {
                    ui->setupUi(this);
                    ui->stackedWidget->setCurrentIndex(0);
                    connect(ui->lineEdit,&QLineEdit::textChanged,this,[this](const QString &tex){
                    lineEdit_textChanged(tex);
                    });
                  }
                  
                  MainWindow::~MainWindow()
                  {
                    delete ui;
                  }
                  
                  
                  void MainWindow::on_pushButton_clicked()
                  {
                      qDebug()<< ui->lineEdit->text();
                      //ui->lineEdit->setText(ui->lineEdit->text());
                  }
                  
                  
                  void MainWindow::lineEdit_textChanged(const QString &arg1)
                  {
                      qDebug()<<"on_lineEdit_textChanged"<<arg1;
                      //ui->lineEdit->blockSignals(true);
                      ui->stackedWidget->setCurrentIndex(1);
                      //ui->lineEdit->blockSignals(false);
                  }
                  
                  
                  
                  JonBJ 1 Reply Last reply
                  0
                  • WenchiW Wenchi

                    @jsulm Here I post the whole code. As you can see I didn't change the lineEdit's text, I still don't understand why there're so many lineEdit_textChanged calls. I can only tell that changing the stackedWidget's current index is the reason which causes so many lineEdit_textChanged calls.

                    #include "mainwindow.h"
                    #include "./ui_mainwindow.h"
                    
                    #include <QDebug>
                    
                    MainWindow::MainWindow(QWidget *parent)
                      : QMainWindow(parent)
                      , ui(new Ui::MainWindow)
                    {
                      ui->setupUi(this);
                      ui->stackedWidget->setCurrentIndex(0);
                      connect(ui->lineEdit,&QLineEdit::textChanged,this,[this](const QString &tex){
                      lineEdit_textChanged(tex);
                      });
                    }
                    
                    MainWindow::~MainWindow()
                    {
                      delete ui;
                    }
                    
                    
                    void MainWindow::on_pushButton_clicked()
                    {
                        qDebug()<< ui->lineEdit->text();
                        //ui->lineEdit->setText(ui->lineEdit->text());
                    }
                    
                    
                    void MainWindow::lineEdit_textChanged(const QString &arg1)
                    {
                        qDebug()<<"on_lineEdit_textChanged"<<arg1;
                        //ui->lineEdit->blockSignals(true);
                        ui->stackedWidget->setCurrentIndex(1);
                        //ui->lineEdit->blockSignals(false);
                    }
                    
                    
                    
                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #8

                    @Wenchi
                    You don't say, but I assume that ui->lineEdit is on stacked widget #0 and there is a another, different page at stacked widget #1?

                    You might get some indication what is going on if you place a breakpoint at the start of lineEdit_textChanged() and look at the stack trace as it keeps getting hit. You should also look at the stack trace when it "crashes".

                    WenchiW 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Wenchi
                      You don't say, but I assume that ui->lineEdit is on stacked widget #0 and there is a another, different page at stacked widget #1?

                      You might get some indication what is going on if you place a breakpoint at the start of lineEdit_textChanged() and look at the stack trace as it keeps getting hit. You should also look at the stack trace when it "crashes".

                      WenchiW Offline
                      WenchiW Offline
                      Wenchi
                      wrote on last edited by
                      #9

                      @JonB the three controls is independent with each other
                      a8e523e7-bbb0-47f5-9bac-6ba0389143cb-企业微信截图_16659984944558.png

                      JonBJ 1 Reply Last reply
                      0
                      • WenchiW Wenchi

                        @JonB the three controls is independent with each other
                        a8e523e7-bbb0-47f5-9bac-6ba0389143cb-企业微信截图_16659984944558.png

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #10

                        @Wenchi
                        So the lineEdit is not on either of the stacked widget pages --- how would we ever have known this? The stacked widget just has two blank QWidgets in it.

                        OK. But what about using the debugger as everyone is saying to see what is going on?

                        Meanwhile: do you just type in test once? Because everything looks like you are appending test to the line edit on textChanged() signal somewhere? Use that debugger to see....

                        WenchiW 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @Wenchi
                          So the lineEdit is not on either of the stacked widget pages --- how would we ever have known this? The stacked widget just has two blank QWidgets in it.

                          OK. But what about using the debugger as everyone is saying to see what is going on?

                          Meanwhile: do you just type in test once? Because everything looks like you are appending test to the line edit on textChanged() signal somewhere? Use that debugger to see....

                          WenchiW Offline
                          WenchiW Offline
                          Wenchi
                          wrote on last edited by Wenchi
                          #11

                          @JonB
                          I insert a break point, and have clicked "run" for 3 times.
                          7addc7b3-57d0-4853-b761-648c57181c4a-企业微信截图_16659999189789.png
                          Then I canceled the breakpoint and run. The stack overflowed and it crashed.
                          By the way, just intput sth by Chinese input method, and don't press "Enter" to make it finish.

                          JonBJ 1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            Bonnie
                            wrote on last edited by
                            #12

                            Wow, surprisingly I can reproduce that even in debug mode. This does seem to have some bug caused by repeatly gaining and losing focus.
                            Only need to type one "test" then output endless

                            [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "test"
                            [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtest"
                            [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtesttest"
                            [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtesttesttest"
                            [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtesttesttesttest"
                            [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtesttesttesttesttest"
                            [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtesttesttesttesttesttest"
                            

                            But I haven't got time to debug it through yet.

                            WenchiW 1 Reply Last reply
                            0
                            • B Bonnie

                              Wow, surprisingly I can reproduce that even in debug mode. This does seem to have some bug caused by repeatly gaining and losing focus.
                              Only need to type one "test" then output endless

                              [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "test"
                              [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtest"
                              [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtesttest"
                              [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtesttesttest"
                              [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtesttesttesttest"
                              [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtesttesttesttesttest"
                              [debug]MainWindow::on_lineEdit_textChanged(126):on_lineEdit_textChanged "testtesttesttesttesttesttest"
                              

                              But I haven't got time to debug it through yet.

                              WenchiW Offline
                              WenchiW Offline
                              Wenchi
                              wrote on last edited by
                              #13

                              @Bonnie I just tried it out yet in debug mode : )

                              1 Reply Last reply
                              0
                              • WenchiW Wenchi

                                @JonB
                                I insert a break point, and have clicked "run" for 3 times.
                                7addc7b3-57d0-4853-b761-648c57181c4a-企业微信截图_16659999189789.png
                                Then I canceled the breakpoint and run. The stack overflowed and it crashed.
                                By the way, just intput sth by Chinese input method, and don't press "Enter" to make it finish.

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by JonB
                                #14

                                @Wenchi
                                If @Bonnie is on it (a) I would guess he is not using "Chinese input method", so that's not it, and (b) he will track it down!

                                But just so I understand (because I do not). You write "under the Chinese input method ", but I don't know what that is/how it works. Do I take it that it shows you that "bar" of possible inputs (numbered 1 to 7), you click on 1 test and that inserts test into the line edit, just once? Since I assume @Bonnie has reproduced without that it does not seem relevant, but I would like to understand.

                                If you look carefully at your stack trace you can see that lineEdit_textChanged() is indeed calling itself recursively, as suspected, hence the eventual "crash".

                                Meanwhile, I would guess --- bug or not --- that there is something "wrong" with "changing focus while you are inside the textChanged() signal handler", something assumes the focus will not change from the QLineEdit it is currently handling. And that somehow makes it keep "re-seeing" the same original test input and adding it. If this is so, you may have to do the ui->stackedWidget->setCurrentIndex(1); call from a QTimer::singleShot() you set off in your slot....

                                WenchiW B 2 Replies Last reply
                                0
                                • JonBJ JonB

                                  @Wenchi
                                  If @Bonnie is on it (a) I would guess he is not using "Chinese input method", so that's not it, and (b) he will track it down!

                                  But just so I understand (because I do not). You write "under the Chinese input method ", but I don't know what that is/how it works. Do I take it that it shows you that "bar" of possible inputs (numbered 1 to 7), you click on 1 test and that inserts test into the line edit, just once? Since I assume @Bonnie has reproduced without that it does not seem relevant, but I would like to understand.

                                  If you look carefully at your stack trace you can see that lineEdit_textChanged() is indeed calling itself recursively, as suspected, hence the eventual "crash".

                                  Meanwhile, I would guess --- bug or not --- that there is something "wrong" with "changing focus while you are inside the textChanged() signal handler", something assumes the focus will not change from the QLineEdit it is currently handling. And that somehow makes it keep "re-seeing" the same original test input and adding it. If this is so, you may have to do the ui->stackedWidget->setCurrentIndex(1); call from a QTimer::singleShot() you set off in your slot....

                                  WenchiW Offline
                                  WenchiW Offline
                                  Wenchi
                                  wrote on last edited by
                                  #15

                                  @JonB
                                  First allow me to explain the "Chinese input method":
                                  When I input "test":
                                  68678bb1-869c-400d-a029-84dffe45e3e9-image.png
                                  Then I can click "1"(or "2" or "3"...) or press "Enter" and the input is finished and this status won't cause crash:
                                  11ce04b2-e558-41bd-896d-35a9ea96564a-image.png
                                  If I click somewhere else, the input is not finished and this status can cause crash:
                                  aed5348d-526b-49f6-89be-464bb42eae1f-image.png
                                  To fix this problem, I add the code "blockSignals":

                                  void MainWindow::lineEdit_textChanged(const QString &arg1)
                                  {
                                      qDebug()<<"on_lineEdit_textChanged"<<arg1;
                                      ui->lineEdit->blockSignals(true);
                                      ui->stackedWidget->setCurrentIndex(1);
                                      ui->lineEdit->blockSignals(false);
                                  }
                                  
                                  JonBJ 1 Reply Last reply
                                  0
                                  • WenchiW Wenchi

                                    @JonB
                                    First allow me to explain the "Chinese input method":
                                    When I input "test":
                                    68678bb1-869c-400d-a029-84dffe45e3e9-image.png
                                    Then I can click "1"(or "2" or "3"...) or press "Enter" and the input is finished and this status won't cause crash:
                                    11ce04b2-e558-41bd-896d-35a9ea96564a-image.png
                                    If I click somewhere else, the input is not finished and this status can cause crash:
                                    aed5348d-526b-49f6-89be-464bb42eae1f-image.png
                                    To fix this problem, I add the code "blockSignals":

                                    void MainWindow::lineEdit_textChanged(const QString &arg1)
                                    {
                                        qDebug()<<"on_lineEdit_textChanged"<<arg1;
                                        ui->lineEdit->blockSignals(true);
                                        ui->stackedWidget->setCurrentIndex(1);
                                        ui->lineEdit->blockSignals(false);
                                    }
                                    
                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on last edited by JonB
                                    #16

                                    @Wenchi
                                    OK, now I know (a bit) about how "Chinese input" works! But I suspect this itself is not the issue, assuming @Bonnie is reproducing the issue.

                                    I am not a great fan of blockSignals(), one is never sure what the side-effects ignoring signals might be. Given that I suggested that QLineEdit might not having like focus changed while inside textChanged() signal, what about the QTimer alternative I suggested instead of blocking signals:

                                    QTimer::singleShot(0, [this]() { ui->stackedWidget->setCurrentIndex(1); });
                                    
                                    WenchiW 1 Reply Last reply
                                    2
                                    • JonBJ JonB

                                      @Wenchi
                                      OK, now I know (a bit) about how "Chinese input" works! But I suspect this itself is not the issue, assuming @Bonnie is reproducing the issue.

                                      I am not a great fan of blockSignals(), one is never sure what the side-effects ignoring signals might be. Given that I suggested that QLineEdit might not having like focus changed while inside textChanged() signal, what about the QTimer alternative I suggested instead of blocking signals:

                                      QTimer::singleShot(0, [this]() { ui->stackedWidget->setCurrentIndex(1); });
                                      
                                      WenchiW Offline
                                      WenchiW Offline
                                      Wenchi
                                      wrote on last edited by
                                      #17

                                      @JonB QTimer::singleShot works! It's more convenient than blockSignals()! Adore you!

                                      JonBJ 1 Reply Last reply
                                      0
                                      • WenchiW Wenchi

                                        @JonB QTimer::singleShot works! It's more convenient than blockSignals()! Adore you!

                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote on last edited by
                                        #18

                                        @Wenchi Thank you, but I am not necessarily very adorable ;-)

                                        1 Reply Last reply
                                        0
                                        • JonBJ JonB

                                          @Wenchi
                                          If @Bonnie is on it (a) I would guess he is not using "Chinese input method", so that's not it, and (b) he will track it down!

                                          But just so I understand (because I do not). You write "under the Chinese input method ", but I don't know what that is/how it works. Do I take it that it shows you that "bar" of possible inputs (numbered 1 to 7), you click on 1 test and that inserts test into the line edit, just once? Since I assume @Bonnie has reproduced without that it does not seem relevant, but I would like to understand.

                                          If you look carefully at your stack trace you can see that lineEdit_textChanged() is indeed calling itself recursively, as suspected, hence the eventual "crash".

                                          Meanwhile, I would guess --- bug or not --- that there is something "wrong" with "changing focus while you are inside the textChanged() signal handler", something assumes the focus will not change from the QLineEdit it is currently handling. And that somehow makes it keep "re-seeing" the same original test input and adding it. If this is so, you may have to do the ui->stackedWidget->setCurrentIndex(1); call from a QTimer::singleShot() you set off in your slot....

                                          B Offline
                                          B Offline
                                          Bonnie
                                          wrote on last edited by Bonnie
                                          #19

                                          @JonB said in QLineEdit combined with QStackedWidget, crash:

                                          If @Bonnie is on it (a) I would guess he is not using "Chinese input method", so that's not it, and (b) he will track it down!

                                          No, I'm using it actually :)
                                          I've done debugging.
                                          Because QStackedWidget::setCurrentIndex calls QWidget::clearFocus which makes the window to emit a focusObjectChanged signal (no matter it actually had the focus or not).
                                          And during the application handling that, it finds the input method composing, so it send a QInputMethodEvent by sendEvent to commit the string and end the composition after that.
                                          But while the line edit handling the event, it emits textChanged again so that never ends.
                                          Not sure whether that is a bug or not...Maybe we are just not supposed to change focus within textChanged()

                                          JonBJ 1 Reply Last reply
                                          3
                                          • B Bonnie

                                            @JonB said in QLineEdit combined with QStackedWidget, crash:

                                            If @Bonnie is on it (a) I would guess he is not using "Chinese input method", so that's not it, and (b) he will track it down!

                                            No, I'm using it actually :)
                                            I've done debugging.
                                            Because QStackedWidget::setCurrentIndex calls QWidget::clearFocus which makes the window to emit a focusObjectChanged signal (no matter it actually had the focus or not).
                                            And during the application handling that, it finds the input method composing, so it send a QInputMethodEvent by sendEvent to commit the string and end the composition after that.
                                            But while the line edit handling the event, it emits textChanged again so that never ends.
                                            Not sure whether that is a bug or not...Maybe we are just not supposed to change focus within textChanged()

                                            JonBJ Offline
                                            JonBJ Offline
                                            JonB
                                            wrote on last edited by
                                            #20

                                            @Bonnie said in QLineEdit combined with QStackedWidget, crash:

                                            No, I'm using it actually :)

                                            Oh! @Bonnie does not sound like a very Chinese name :)

                                            Maybe we are just not supposed to change focus within textChanged()

                                            That is evidently the case. For whatever reason, it appears the internals expect the line edit to have the focus while dealing with textChanged(), and changing it causes the signal to be re-emitted.

                                            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