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. ui->... crashes my app
Qt 6.11 is out! See what's new in the release blog

ui->... crashes my app

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 2.4k 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.
  • M Offline
    M Offline
    Manaan
    wrote on last edited by
    #1

    Okay, here's what i've got now: a simple app with 2 classes, where 1 class calls a function out of another. It all works pretty good, but the function I'm acessing is supposed to access and change the plainTextEdit's text.
    I've been using:
    ui->plainTextEdit->setPlainText(text);
    ui->plainTextEdit->document()->setPlainText(text);

    but both are crashing my app when run.
    even such things as:
    ui->plainTextEdit->clear()
    or
    QPlainTextEdit *text1 = this->ui->plainTextEdit
    crashes the app, while compiler says everything is alright.

    Any ideas what in ui->... can cause crashes?

    1 Reply Last reply
    0
    • W Offline
      W Offline
      wrosecrans
      wrote on last edited by
      #2

      For starters, what's UI?

      If you run in the debugger, is UI a valid instance of whatever it is, or is ui null?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Manaan
        wrote on last edited by
        #3

        ui is used like that

        MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
        }
        

        when I write ui-> the helper suggests me elements I have on the form, so I suggest it is the good way to access controls on a window. Is it?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Manaan
          wrote on last edited by
          #4

          Finally debugged and figured out the thing.
          In the other class I'm getting .allWindows to QList and get [0] from that list(Got only 1 window in my app). After that, I want to execute a function defined for that window, so I qcast it from QWindow to QMainWindow. And that does not work.
          Will placing both classes in one file and making "ui" global do the trick?

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wrosecrans
            wrote on last edited by
            #5

            You still haven't answered what ui is. Figuring that out may help you.

            I qcast it from QWindow to QMainWindow.

            Those are two completely different classes, so casting a pointer from one type to the other is just lying to the compiler about what the pointer is pointing at! It should be very rare that you would ever want to do something like that.

            1 Reply Last reply
            4

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved