ui->... crashes my app



  • 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?



  • For starters, what's UI?

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



  • 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?



  • 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?



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.