Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Question about QDataStream and its functions startTransaction and commitTransaction
Qt 6.12 LTS is out! See what's new in the release blog

Question about QDataStream and its functions startTransaction and commitTransaction

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 632 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.
  • J Offline
    J Offline
    Jc_Opc
    wrote on last edited by
    #1

    Hi,
    I found the following code in the example https://code.qt.io/cgit/qt/qtbase.git/tree/examples/network/fortuneclient/client.cpp?h=5.15,

    ...
    connect(tcpSocket, &QIODevice::readyRead, this, &Client::readFortune);
    ...
    void Client::readFortune()
    {
        in.startTransaction();
    
        QString nextFortune;
        in >> nextFortune;
    
        if (!in.commitTransaction())
            return;
    
        if (nextFortune == currentFortune) {
            QTimer::singleShot(0, this, &Client::requestNewFortune);
            return;
        }
    
        currentFortune = nextFortune;
        statusLabel->setText(currentFortune);
        getFortuneButton->setEnabled(true);
    }
    

    The issue I am having is in.commitTransaction() always return false, the size of the tcpsocket buffer keeps increasing and nextFortune size is always 0.

    Any help I really appreciate it.

    Thanks

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      So how do you send your data?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

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