0

I'm writing two programs on Qt 5. The first ("Debug") program sends requests to the second ("Simulator") through a PCI-E device. The "Simulator" must respond as fast as possible. This is a separate issue, but now I want to ask about another strange effect. The "Debug" program writes 10 bytes from QLineEdit to a PCI-E device and then waits for an answer from the "Simulator". When the answer came fast enough, I see the right data bytes in the "Debug" program window, otherwise a PCI-E device returns a copy of a sended data and I see it too. The issue is that data can be sended by two ways: by clicking the Send button on the form and by clicking the Return button on a keyboard. In both cases the data is sent from the following slot:

void MyWin::on_pushButton_Send_clicked()
{
    if(data_matched)
    {
        QString exp = ui.lineEdit_Data->text();

        QStringList list = exp.split(QRegExp("\\s"), 
            QString::SkipEmptyParts);

        for(int i=0; i<list.size(); i++)
        {
            quint8 a = list[i].toUInt(0, 16);
            data[i] = a;
        }

        write_insys(bHandle, data, DataSize);

        ui.textEdit->append( /* show sended bytes */ );       

        read_insys(bHandle, data, DataSize);

        ui.textEdit->append( /* show received bytes */ );
    }
}

But in the second case (on Return key press) the only difference is that the above slot is invoked inside the following:

void MyWin::on_lineEdit_Data_returnPressed()
{
    on_pushButton_Send_clicked();
}

But the results:

  • 1st case: 90% wrong answers
  • 2st case: 90% right answers

The code of write_insys and read_insys is absolutely trivial, simply call the library functions:

bool write_insys(BRD_Handle handle, void* data, int size)
{
    S32 res = BRD_putMsg(handle, NODE0, data, (U32*)&size, BRDtim_FOREVER);

    return (res >= 0);
}

bool read_insys(BRD_Handle handle, void* data, int size)
{
    S32 res = BRD_getMsg(handle, NODE0, data, (U32*)&size, BRDtim_FOREVER);

    return (res >= 0);
}

Does anyone know why this might happen?
Windows 7, Qt 5.4.2, Msvc 2010.

edit: Most likely it is a Qt bug...

Vladimir Bershov
  • 2,701
  • 2
  • 21
  • 51
  • Is your `exp` variable same in both cases? – Kirill Chernikov Dec 19 '16 at 12:33
  • @KirillChernikov, yes – Vladimir Bershov Dec 19 '16 at 12:34
  • It looks all right in your code. Maybe, bug on the "Simulator" side or inside `write_insys` or `read_insys`. – Kirill Chernikov Dec 19 '16 at 12:35
  • @KirillChernikov, but the Simulator receive (and send) exactly the same data in both cases (and I see it in its terminal textEdit) – Vladimir Bershov Dec 19 '16 at 12:44
  • 1
    It's impossible to answer this question without seeing more of the code - e.g. a minimal test case that reproduces it. When you truly minimize things, both the debug and simulator would be a single executable, with a single `main.cpp` file that is under 300 lines long. That would have some chance at making a decent question. Otherwise it's off-topic here. The diagnosis of "most likely it's a Qt bug" is unfounded. – Kuba hasn't forgotten Monica Dec 19 '16 at 17:32

0 Answers0