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

GUI app and QTcpSocket

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.0k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    blks303
    wrote on last edited by
    #1

    Hi everyone,
    Before describing my problem I have to say I am completely new to Qt and my experience with C++ is limited to firmware for micro-controllers so please don't be mean :)
    I am trying to build a small GUI app able to connect to a power supply through TCP/IP, read its status and change the output current.
    What I need on the GUI is tow push buttons: connect disconnect, and a scroll bar to set the output current of the power supply.

    I followed these tutorials on youtube C++ Qt 65 - QTcpSocket basics, C++ Qt 66 - QTCPSocket using signals and slots and I manage to establish a connection and also send some commands to the power supply.
    My problem now is that I am not able to use signals and slots between the gui and the QTcpSocket commands.

    I know this seems a pretty basic problem and is probably related to my pure Cpp knowledge than Qt it self, but I red lots of other tutorials and wikis and still I am very confused and don't really know from where to start in the code.

    There are probably other simpler ways of doing this but I am very keen on learning Qt.

    Any Kind of help would be very much appreciated.

    Cheers

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      I will assume you are using a QSlider to change the output current of your power supply.

      One of the usual way to do it is to add a slot to your widget and connect your slider to it

      MyWindow::MyWindow(QWidget *parent)
          : QWidget(parent)
      {
          QSlider *currentSlider = new QSlider;
          QVBoxLayout *layout = new QVBoxLayout(this);
          layout->addWidget(currentSlider);
          connect(currentSlider, &QSlider::valueChanged, this, &MyWindow::onSliderValueChanged);
      }
      void MyWindow::onSliderValueChanged(int currentValue)
      {
          QByteArray cmd = "something" + QByteArray::number(currentValue); // To be replaced by the real command you need to send to the device.
          _myTcpSocket->write(cmd);
      }
      

      Hope it helps.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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