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. Segmentation fault while accessing textBox from callback
Forum Updated to NodeBB v4.3 + New Features

Segmentation fault while accessing textBox from callback

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 5 Posters 966 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.
  • C Offline
    C Offline
    column
    wrote on last edited by
    #1

    I have simple callback functions that provides data to be shown on QT widget main form. As soon breakpoint reaches setText() I have exception Segmentation fault:

    void MainWindow::SetAmount(int value)
    {
        ui->tbAmount->setText( QString::number(value) );
    
    }
    

    enter image description here

    Why I'm geting souch error? When I call SetAmount() from button click it runs fine.

    JonBJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Do you call it from another thread?

      C 1 Reply Last reply
      4
      • C column

        I have simple callback functions that provides data to be shown on QT widget main form. As soon breakpoint reaches setText() I have exception Segmentation fault:

        void MainWindow::SetAmount(int value)
        {
            ui->tbAmount->setText( QString::number(value) );
        
        }
        

        enter image description here

        Why I'm geting souch error? When I call SetAmount() from button click it runs fine.

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

        @column said in Segmentation fault while accessing textBox from callback:

        As soon breakpoint reaches setText()

        Do you mean when it hits breakpoint on that line before it executes the line, or do you mean as it executes that line?

        But answer @mrjj first.

        C 1 Reply Last reply
        1
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @column said in Segmentation fault while accessing textBox from callback:

          ui->tbAmount

          I would guess the either ui or ui->tbAmount is not initialized.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          4
          • mrjjM mrjj

            Hi
            Do you call it from another thread?

            C Offline
            C Offline
            column
            wrote on last edited by
            #5

            @mrjj I suppose this callback that comes from .so library might be from other thread. Is that problem? How to solve it then?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Yes that is a problem, GUI elements should only be accessed/modified in the GUI thread. The cleanest way would be to use QMetaObject::invokeMethod using QueuedConnection so you ensure that the setText will be called in the correct context.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2
              • JonBJ JonB

                @column said in Segmentation fault while accessing textBox from callback:

                As soon breakpoint reaches setText()

                Do you mean when it hits breakpoint on that line before it executes the line, or do you mean as it executes that line?

                But answer @mrjj first.

                C Offline
                C Offline
                column
                wrote on last edited by column
                #7

                @JonB I mean "as it executes that line"

                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