How to Send and Receive data from Different files



  • Hello All,

    I am new to the Qt/QML, i am getting the value from mainwindow.cpp and i have function or file( i don't know, shall i make it in function or file below code for brightness please suggest me) for reduce the brightness of display i.e
    /* code for brightness /
    QFile f("/sys/class/backlight/mi-bl/brightness");
    f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
    f.write("200"); // it is change at runtime
    f.flush();
    f.close();
    /
    ********************* */
    and i am getting the data from serial port i.e,

    void SerialPortReader::handleReadyRead()
    {
    QByteArray data;
    data.resize(40);
    QString str;
    data = m_serialPort->readAll();
    str = data;
    }

    i want to send a parameter str to f.write(*** ); and data is change frequently at runtime how do this task, please any one have solution please guide me,

    Best Regards,
    Nandish sg



  • Hi @nandishsg

    Maybe you are looking for SIGNAL/SLOT, just after str = data;

    emit backlightValueReceived(str);//send str value
    

    and then on your MainWindow.cpp you need to have a slot:

    onBacklightValueReceived(const str  &backlightValue)
    {
    .
    .
    .
    f.write(str);
    .
    .
    .
    }
    

    But best way would be to have a class : Backlight, and to have writeValue(str) called just after str = data, instead of having everything in mainWindow;

    I hope this can help you


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.