Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Print to screen from qDebug



  • QProcess process;
    

    process.start("sudo devmem2 0x80000000");
    process.waitForFinished(-1); // will wait forever until finished

    QString stdout = process.readAllStandardOutput();
    QString stderr = process.readAllStandardError();

    qDebug() << stdout;
    ui->lineEdit->setText(qDebug());
    

    I want to display my qDebug to lineEdit in Qt.



  • @Mijaz
    Your stdout is just a QString. So why qDebug()? You just need ui->lineEdit->setText(stdout);.



  • Hi @JonB Thanks, it works...

    Can I define range like this?
    ui->lineEdit->setText(stdout[90:105]);



  • @Mijaz
    Where does QString (or C++) define a [start:end] "range operator"? Since it does not (you're not in Python!), no you cannot do that. Read the docs for QString, e.g. https://doc.qt.io/qt-5/qstring.html#mid.


  • Moderators

    @JonB not yet, but there's an awful amount of talking about it for c++20 ....



  • @J-Hilk
    Just great. C was fine, let's make C++ more like hideous Python... ;-)


  • Moderators

    @JonB well, that's one way of looking at it, I think its nice, that after 35 Years, the user base still grows and the language still adapts new features :)

    look at this beauty and tell me its hideous :P

    int main()
    {
        std::vector<int> ints{0,1,2,3,4,5};
        auto even = [](int i){ return 0 == i % 2; };
        auto square = [](int i) { return i * i; };
     
        for (int i : ints | std::views::filter(even) | std::views::transform(square)) {
            std::cout << i << ' ';
        }
    }
    
    //Output: 0 4 16
    


  • @J-Hilk
    This is probably not the place for a discussion, but yes I think it's hard to read/understand. WTF is that | logical-or operator doing in the for against arrays? (Yes, I can guess...) Is it really easier to read or more efficient than an if inside the loop? Depending on how that for ( ... | ...) is implemented, it could be hideously inefficient!


Log in to reply