Solved How to call pushbutton in main.cpp
-
I want to start the server when I press "Start" button.How to do it?
int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget widget; QLineEdit *pLineEditPortNumber = new QLineEdit; pLineEditPortNumber->setPlaceholderText("Enter Port Number"); pLineEditPortNumber->setInputMask("99999"); QPushButton *pPushButtonStart = new QPushButton("Start"); QVBoxLayout *pVBoxLayoutMain = new QVBoxLayout; pVBoxLayoutMain->addWidget(pLineEditPortNumber); pVBoxLayoutMain->addWidget(pPushButtonStart); widget.setLayout(pVBoxLayoutMain); MyServer Server; Server.StartServer(); widget.show(); return a.exec(); }
-
hi @asttekin
Easy enough I think ;-)
QObject::connect(pPushButtonStart, &QPushButton::clicked, &Server, &MyServer::StartServer);
as main is not derived from QObject, you have to use the Static connect call.
-
Thanks.Well, how to pass the portNumber to StartServer.
-
QObject::connect(pLineEditPortNumber, &QLineEdit::textEdited, &Server, &MyServer::setPort); // assumption setPort exists and accepts an QString
-
thank you so much.