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. How to call pushbutton in main.cpp

How to call pushbutton in main.cpp

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

    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();
    }
    
    J.HilkJ 1 Reply Last reply
    0
    • asttekinA asttekin

      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();
      }
      
      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      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.


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      4
      • asttekinA Offline
        asttekinA Offline
        asttekin
        wrote on last edited by
        #3

        Thanks.Well, how to pass the portNumber to StartServer.

        J.HilkJ 1 Reply Last reply
        0
        • asttekinA asttekin

          Thanks.Well, how to pass the portNumber to StartServer.

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @asttekin

          QObject::connect(pLineEditPortNumber, &QLineEdit::textEdited, &Server, &MyServer::setPort); // assumption setPort exists and accepts an QString
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          4
          • asttekinA Offline
            asttekinA Offline
            asttekin
            wrote on last edited by
            #5

            thank you so much.

            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