简体   繁体   中英

Can't access a control in a widget from another widget in Qt

I have this widget in Qt:

"connecttoserver.h"
"connecttoserver.cpp"
"connecttoserver.ui"

and this one:

"mainwindow.h"
"mainwindow.cpp"
"mainwindow.ui"

How can I access the "connectToserver" elements from the "mainwindow" widget?

I've tried doing this:

void MainWindow::on_btnLogin_clicked()
{
    connectToserver ccc;
    ccc.ui.txt_mail_ip.text();
}

But it doesn't work.

It's C++: to access one widget member from another widget, just create a method (or a Qt slot, if you prefer) and invoke it from the other widget. For being accessible, the method (or the slot) mut be public, or otherwise the two classes must be friend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM