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. how to capture bluetooth command text selection running in QProcess ?
Forum Updated to NodeBB v4.3 + New Features

how to capture bluetooth command text selection running in QProcess ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 4 Posters 1.3k 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.
  • A Anonymous_Banned275

    Another addendum - for discussion purpose.

    I may have found PART of my problem)((s).

    1. If I remove the "info" options I get this:

    cb162144-fdf7-4701-8b7f-6fb75a7b7b99-image.png

    That is definitely outside of main QT process. I have been calling it "OS window" .

    1. My MDI child is derived from QTextEdit and this so far unknown window is what ??

    Obviously not suitable to be derived from QTextEdit, but what ?

    Eventually I will have MDI child process accessing an internet (GUI) application - so for now I need to try bluetrootctl command to be something different then QTextEdit.

    Here is the actual response to "no into" - the MDI child is build AFTER Ubuntu OS decides to let QT "respond" - that is KNOWN Ubuntu issue.

    5f2ef69f-197f-486b-82e9-c6db9a983235-image.png

    Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #5

    @AnneRanch said in how to capture bluetooth command text selection running in QProcess ?:

    Here is the actual response to "no into" - the MDI child is build AFTER Ubuntu OS decides to let QT "respond" - that is KNOWN Ubuntu issue.

    When you don't pass the -ìnto -parameter a new xterm is opened, what do you expect otherwise?

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

    A 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @AnneRanch said in how to capture bluetooth command text selection running in QProcess ?:

      Here is the actual response to "no into" - the MDI child is build AFTER Ubuntu OS decides to let QT "respond" - that is KNOWN Ubuntu issue.

      When you don't pass the -ìnto -parameter a new xterm is opened, what do you expect otherwise?

      A Offline
      A Offline
      Anonymous_Banned275
      wrote on last edited by
      #6

      @Christian-Ehrlicher said in how to capture bluetooth command text selection running in QProcess ?:

      @AnneRanch said in how to capture bluetooth command text selection running in QProcess ?:

      Here is the actual response to "no into" - the MDI child is build AFTER Ubuntu OS decides to let QT "respond" - that is KNOWN Ubuntu issue.

      When you don't pass the -ìnto -parameter a new xterm is opened, what do you expect otherwise?

      PLEASE stay on subject.

      The purpose of my post was to solicit guesses / opinions if changing the MDI QTextEdit to other class would solve the problem.

      Christian EhrlicherC 1 Reply Last reply
      0
      • A Anonymous_Banned275

        @Christian-Ehrlicher said in how to capture bluetooth command text selection running in QProcess ?:

        @AnneRanch said in how to capture bluetooth command text selection running in QProcess ?:

        Here is the actual response to "no into" - the MDI child is build AFTER Ubuntu OS decides to let QT "respond" - that is KNOWN Ubuntu issue.

        When you don't pass the -ìnto -parameter a new xterm is opened, what do you expect otherwise?

        PLEASE stay on subject.

        The purpose of my post was to solicit guesses / opinions if changing the MDI QTextEdit to other class would solve the problem.

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #7

        @AnneRanch said in how to capture bluetooth command text selection running in QProcess ?:

        to other class would solve the problem.

        And we told you nearly a hundred times that this is not possible. The only way to get information from the other process is via the clipboard.

        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
        1
        • A Offline
          A Offline
          Anonymous_Banned275
          wrote on last edited by
          #8

          ADDENDUM

          Here is my current code responding to xterm bluetoothctl command as "SIGNAL TextChanged". The class is QTextEdit and I am looking for a way to involve clipboard.
          I can either add clipboard into "TextChanged" - preferred , there are other functions processing text - or change the MDI child from QTextEdit to something more friendly to clipboard processing.

          d4c1b923-e44a-488d-a397-20d4438c35c7-image.png

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by ChrisW67
            #9

            There is no relationship between the QTextEdit, or whatever else you put in the QMdiSubWindow, and the separate operating system process you start (xterm) other than that you have directed that process to render its output on the screen in the same location as the QMdiSubWindow.

            There is no relationship between the input/output streams of the xterm you have launched with QProcess and the input/output streams of the process or processes being run internally by xterm. So, for example, xterm does not send anything to standard out when it is asked, as you do, to execute bluetoothctl inside even though bluetoothctl does output (see example below).
            2b8a687a-d46c-4889-b4a3-40d36d55dd56-image.png
            You therefore cannot access the bluetoothctl output through the QProcess instance.

            Here is a complete example widget that captures the output into a QTextEdit and can see the selections/clipboard.

            #ifndef DEMOWIDGET_H
            #define DEMOWIDGET_H
            
            #include <QWidget>
            #include <QTextEdit>
            #include <QProcess>
            
            class DemoWidget : public QWidget
            {
                Q_OBJECT
            
            public:
                DemoWidget(QWidget *parent = nullptr);
                ~DemoWidget();
            
            private slots:
                void startProcess();
                void handleOutput();
                void finishedOutput();
                void handleSelection();
            
            private:
                QTextEdit *m_textEdit;
                QTextEdit *m_selectedEdit;
                QProcess *m_process;
                QByteArray buffer;
            };
            #endif // DEMOWIDGET_H
            
            #include "demowidget.h"
            
            #include <QVBoxLayout>
            #include <QTimer>
            #include <QStandardPaths>
            #include <QClipboard>
            #include <QGuiApplication>
            
            DemoWidget::DemoWidget(QWidget *parent)
                : QWidget(parent)
                , m_textEdit(nullptr)
                , m_selectedEdit(nullptr)
                , m_process(nullptr)
            {
                m_textEdit = new QTextEdit(this);
                m_textEdit->setLineWrapMode(QTextEdit::NoWrap);
                m_textEdit->setAcceptRichText(false);
                m_textEdit->setReadOnly(true);
                connect(m_textEdit, &QTextEdit::selectionChanged, this, &DemoWidget::handleSelection);
            
                m_selectedEdit = new QTextEdit(this);
                m_selectedEdit->setLineWrapMode(QTextEdit::NoWrap);
                m_selectedEdit->setAcceptRichText(false);
                m_selectedEdit->setReadOnly(true);
            
                QVBoxLayout *layout = new QVBoxLayout(this);
                layout->addWidget(m_textEdit);
                layout->setStretchFactor(m_textEdit, 4);
                layout->addWidget(m_selectedEdit);
                layout->setStretchFactor(m_selectedEdit, 1);
            
                resize(1024, 768);
            
                QTimer::singleShot(1000, this, &DemoWidget::startProcess);
            }
            
            DemoWidget::~DemoWidget()
            {
            }
            
            void DemoWidget::startProcess()
            {
                m_process = new QProcess(this);
                connect(m_process, &QProcess::readyReadStandardOutput, this, &DemoWidget::handleOutput);
                connect(m_process, &QProcess::finished, this, &DemoWidget::finishedOutput);
            
                QStringList args = QStringList() << "-l" << QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0);
                m_process->start("/usr/bin/ls", args);
            }
            
            void DemoWidget::handleOutput()
            {
                QByteArray processOutput = m_process->readAllStandardOutput();
                m_textEdit->append(QString::fromUtf8(processOutput));
            }
            
            void DemoWidget::finishedOutput()
            {
                m_textEdit->append(QStringLiteral("\n\n=====\nFinished"));
            }
            
            void DemoWidget::handleSelection()
            {
                // will work on Linux only, rough demo only
                QClipboard *clipboard = QGuiApplication::clipboard();
                m_selectedEdit->setPlainText(clipboard->text(QClipboard::Selection));
            }
            
            

            No intervening xterm, no separate processes rendering into a Qt window, no problem accessing the text in the edit. This is a way to address what you are trying to do, but what you are trying to do is probably not the best solution to your actual problem... you could not make QBluetooth work.

            This post proudly sponsored by XY Problem

            JonBJ A 3 Replies Last reply
            0
            • C ChrisW67

              There is no relationship between the QTextEdit, or whatever else you put in the QMdiSubWindow, and the separate operating system process you start (xterm) other than that you have directed that process to render its output on the screen in the same location as the QMdiSubWindow.

              There is no relationship between the input/output streams of the xterm you have launched with QProcess and the input/output streams of the process or processes being run internally by xterm. So, for example, xterm does not send anything to standard out when it is asked, as you do, to execute bluetoothctl inside even though bluetoothctl does output (see example below).
              2b8a687a-d46c-4889-b4a3-40d36d55dd56-image.png
              You therefore cannot access the bluetoothctl output through the QProcess instance.

              Here is a complete example widget that captures the output into a QTextEdit and can see the selections/clipboard.

              #ifndef DEMOWIDGET_H
              #define DEMOWIDGET_H
              
              #include <QWidget>
              #include <QTextEdit>
              #include <QProcess>
              
              class DemoWidget : public QWidget
              {
                  Q_OBJECT
              
              public:
                  DemoWidget(QWidget *parent = nullptr);
                  ~DemoWidget();
              
              private slots:
                  void startProcess();
                  void handleOutput();
                  void finishedOutput();
                  void handleSelection();
              
              private:
                  QTextEdit *m_textEdit;
                  QTextEdit *m_selectedEdit;
                  QProcess *m_process;
                  QByteArray buffer;
              };
              #endif // DEMOWIDGET_H
              
              #include "demowidget.h"
              
              #include <QVBoxLayout>
              #include <QTimer>
              #include <QStandardPaths>
              #include <QClipboard>
              #include <QGuiApplication>
              
              DemoWidget::DemoWidget(QWidget *parent)
                  : QWidget(parent)
                  , m_textEdit(nullptr)
                  , m_selectedEdit(nullptr)
                  , m_process(nullptr)
              {
                  m_textEdit = new QTextEdit(this);
                  m_textEdit->setLineWrapMode(QTextEdit::NoWrap);
                  m_textEdit->setAcceptRichText(false);
                  m_textEdit->setReadOnly(true);
                  connect(m_textEdit, &QTextEdit::selectionChanged, this, &DemoWidget::handleSelection);
              
                  m_selectedEdit = new QTextEdit(this);
                  m_selectedEdit->setLineWrapMode(QTextEdit::NoWrap);
                  m_selectedEdit->setAcceptRichText(false);
                  m_selectedEdit->setReadOnly(true);
              
                  QVBoxLayout *layout = new QVBoxLayout(this);
                  layout->addWidget(m_textEdit);
                  layout->setStretchFactor(m_textEdit, 4);
                  layout->addWidget(m_selectedEdit);
                  layout->setStretchFactor(m_selectedEdit, 1);
              
                  resize(1024, 768);
              
                  QTimer::singleShot(1000, this, &DemoWidget::startProcess);
              }
              
              DemoWidget::~DemoWidget()
              {
              }
              
              void DemoWidget::startProcess()
              {
                  m_process = new QProcess(this);
                  connect(m_process, &QProcess::readyReadStandardOutput, this, &DemoWidget::handleOutput);
                  connect(m_process, &QProcess::finished, this, &DemoWidget::finishedOutput);
              
                  QStringList args = QStringList() << "-l" << QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0);
                  m_process->start("/usr/bin/ls", args);
              }
              
              void DemoWidget::handleOutput()
              {
                  QByteArray processOutput = m_process->readAllStandardOutput();
                  m_textEdit->append(QString::fromUtf8(processOutput));
              }
              
              void DemoWidget::finishedOutput()
              {
                  m_textEdit->append(QStringLiteral("\n\n=====\nFinished"));
              }
              
              void DemoWidget::handleSelection()
              {
                  // will work on Linux only, rough demo only
                  QClipboard *clipboard = QGuiApplication::clipboard();
                  m_selectedEdit->setPlainText(clipboard->text(QClipboard::Selection));
              }
              
              

              No intervening xterm, no separate processes rendering into a Qt window, no problem accessing the text in the edit. This is a way to address what you are trying to do, but what you are trying to do is probably not the best solution to your actual problem... you could not make QBluetooth work.

              This post proudly sponsored by XY Problem

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by JonB
              #10

              @ChrisW67
              We have already explained this to the OP. Back in September in https://forum.qt.io/topic/139374/another-xterm-qtextedit-issues/10 I took the time to write just what she needs for running the bluetoothctl, capturing its input/output, removing the ANSI "color" control sequences it emits, and displaying its output in a QTextEdit. It also shows a screenshot of what it looks like for a small exchange.
              alt text

              Because I wanted to be helpful. Obviously it's dead easy to add cut/copy/paste between such a QTextEdit and other windows if desired. Explained why using xterm is the wrong way to go. Asked her to just try it for herself so she could see. But was told

              **PLEASE - If your know the answer post it... other contributions are superfluous at this point **

              1 Reply Last reply
              1
              • C ChrisW67

                There is no relationship between the QTextEdit, or whatever else you put in the QMdiSubWindow, and the separate operating system process you start (xterm) other than that you have directed that process to render its output on the screen in the same location as the QMdiSubWindow.

                There is no relationship between the input/output streams of the xterm you have launched with QProcess and the input/output streams of the process or processes being run internally by xterm. So, for example, xterm does not send anything to standard out when it is asked, as you do, to execute bluetoothctl inside even though bluetoothctl does output (see example below).
                2b8a687a-d46c-4889-b4a3-40d36d55dd56-image.png
                You therefore cannot access the bluetoothctl output through the QProcess instance.

                Here is a complete example widget that captures the output into a QTextEdit and can see the selections/clipboard.

                #ifndef DEMOWIDGET_H
                #define DEMOWIDGET_H
                
                #include <QWidget>
                #include <QTextEdit>
                #include <QProcess>
                
                class DemoWidget : public QWidget
                {
                    Q_OBJECT
                
                public:
                    DemoWidget(QWidget *parent = nullptr);
                    ~DemoWidget();
                
                private slots:
                    void startProcess();
                    void handleOutput();
                    void finishedOutput();
                    void handleSelection();
                
                private:
                    QTextEdit *m_textEdit;
                    QTextEdit *m_selectedEdit;
                    QProcess *m_process;
                    QByteArray buffer;
                };
                #endif // DEMOWIDGET_H
                
                #include "demowidget.h"
                
                #include <QVBoxLayout>
                #include <QTimer>
                #include <QStandardPaths>
                #include <QClipboard>
                #include <QGuiApplication>
                
                DemoWidget::DemoWidget(QWidget *parent)
                    : QWidget(parent)
                    , m_textEdit(nullptr)
                    , m_selectedEdit(nullptr)
                    , m_process(nullptr)
                {
                    m_textEdit = new QTextEdit(this);
                    m_textEdit->setLineWrapMode(QTextEdit::NoWrap);
                    m_textEdit->setAcceptRichText(false);
                    m_textEdit->setReadOnly(true);
                    connect(m_textEdit, &QTextEdit::selectionChanged, this, &DemoWidget::handleSelection);
                
                    m_selectedEdit = new QTextEdit(this);
                    m_selectedEdit->setLineWrapMode(QTextEdit::NoWrap);
                    m_selectedEdit->setAcceptRichText(false);
                    m_selectedEdit->setReadOnly(true);
                
                    QVBoxLayout *layout = new QVBoxLayout(this);
                    layout->addWidget(m_textEdit);
                    layout->setStretchFactor(m_textEdit, 4);
                    layout->addWidget(m_selectedEdit);
                    layout->setStretchFactor(m_selectedEdit, 1);
                
                    resize(1024, 768);
                
                    QTimer::singleShot(1000, this, &DemoWidget::startProcess);
                }
                
                DemoWidget::~DemoWidget()
                {
                }
                
                void DemoWidget::startProcess()
                {
                    m_process = new QProcess(this);
                    connect(m_process, &QProcess::readyReadStandardOutput, this, &DemoWidget::handleOutput);
                    connect(m_process, &QProcess::finished, this, &DemoWidget::finishedOutput);
                
                    QStringList args = QStringList() << "-l" << QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0);
                    m_process->start("/usr/bin/ls", args);
                }
                
                void DemoWidget::handleOutput()
                {
                    QByteArray processOutput = m_process->readAllStandardOutput();
                    m_textEdit->append(QString::fromUtf8(processOutput));
                }
                
                void DemoWidget::finishedOutput()
                {
                    m_textEdit->append(QStringLiteral("\n\n=====\nFinished"));
                }
                
                void DemoWidget::handleSelection()
                {
                    // will work on Linux only, rough demo only
                    QClipboard *clipboard = QGuiApplication::clipboard();
                    m_selectedEdit->setPlainText(clipboard->text(QClipboard::Selection));
                }
                
                

                No intervening xterm, no separate processes rendering into a Qt window, no problem accessing the text in the edit. This is a way to address what you are trying to do, but what you are trying to do is probably not the best solution to your actual problem... you could not make QBluetooth work.

                This post proudly sponsored by XY Problem

                A Offline
                A Offline
                Anonymous_Banned275
                wrote on last edited by
                #11

                @ChrisW67 Thanks.

                After briefly reading you excellent post I still do not get how I can highlight specific text, using mouse, and not be able to detect that by any means - using OS or mouse (down) . If event ( highlight) happens there MUST be a way to detect it.

                I went thru the MDI example code and found this line

                CCC_MdiChild *CCC_MainWindow::createMdiChild()
                {
                
                    // insert  new child here ??
                #ifdef TRACE_MDI_XTERM
                    qDebug()<< "TRACE_MDI_XTERM  "  <<Q_FUNC_INFO;
                    qDebug()<< "TRACE_MDI_XTERM  @line "  << QString::number(__LINE__);
                    qDebug()<< "TRACE_MDI_XTERM insert  new child here ??  @line "  << QString::number(__LINE__);
                #endif
                    CCC_MdiChild *child = new CCC_MdiChild;
                    mdiArea->addSubWindow(child);
                    // ??
                    here
                #ifndef QT_NO_CLIPBOARD
                    connect(child, &QTextEdit::copyAvailable, cutAct, &QAction::setEnabled);
                    connect(child, &QTextEdit::copyAvailable, copyAct, &QAction::setEnabled);
                #endif
                
                    return child;
                }
                

                Since the code is poorly documented I have no clue what / how is this used .
                I'll looking into it.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Anonymous_Banned275
                  wrote on last edited by
                  #12

                  I would like to concentrate on SPECIFIC problem - if possible.
                  It may or may not lead to problem solution.

                  I can detect mouse movement SIGNAL -after it enters the "Black frame".
                  I have a function to process "mouse down" but it never executes.
                  BUT if either mouse button is pressed - "mouse move" is NOT generated - hence the button(s) are acknowledged somehow.

                  HOWEVER - I am getting this run time message
                  "Selection too old..." and like to identify where it is coming from .

                  cccb9fda-bad2-4c60-88df-bc6ea1e7d799-image.png

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • A Anonymous_Banned275

                    I would like to concentrate on SPECIFIC problem - if possible.
                    It may or may not lead to problem solution.

                    I can detect mouse movement SIGNAL -after it enters the "Black frame".
                    I have a function to process "mouse down" but it never executes.
                    BUT if either mouse button is pressed - "mouse move" is NOT generated - hence the button(s) are acknowledged somehow.

                    HOWEVER - I am getting this run time message
                    "Selection too old..." and like to identify where it is coming from .

                    cccb9fda-bad2-4c60-88df-bc6ea1e7d799-image.png

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #13

                    @AnneRanch said in how to capture bluetooth command text selection running in QProcess ?:

                    I can detect mouse movement SIGNAL -after it enters the "Black frame".

                    For the nth time: the 'black frame' is another application where you don't have control of it.

                    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
                    • C ChrisW67

                      There is no relationship between the QTextEdit, or whatever else you put in the QMdiSubWindow, and the separate operating system process you start (xterm) other than that you have directed that process to render its output on the screen in the same location as the QMdiSubWindow.

                      There is no relationship between the input/output streams of the xterm you have launched with QProcess and the input/output streams of the process or processes being run internally by xterm. So, for example, xterm does not send anything to standard out when it is asked, as you do, to execute bluetoothctl inside even though bluetoothctl does output (see example below).
                      2b8a687a-d46c-4889-b4a3-40d36d55dd56-image.png
                      You therefore cannot access the bluetoothctl output through the QProcess instance.

                      Here is a complete example widget that captures the output into a QTextEdit and can see the selections/clipboard.

                      #ifndef DEMOWIDGET_H
                      #define DEMOWIDGET_H
                      
                      #include <QWidget>
                      #include <QTextEdit>
                      #include <QProcess>
                      
                      class DemoWidget : public QWidget
                      {
                          Q_OBJECT
                      
                      public:
                          DemoWidget(QWidget *parent = nullptr);
                          ~DemoWidget();
                      
                      private slots:
                          void startProcess();
                          void handleOutput();
                          void finishedOutput();
                          void handleSelection();
                      
                      private:
                          QTextEdit *m_textEdit;
                          QTextEdit *m_selectedEdit;
                          QProcess *m_process;
                          QByteArray buffer;
                      };
                      #endif // DEMOWIDGET_H
                      
                      #include "demowidget.h"
                      
                      #include <QVBoxLayout>
                      #include <QTimer>
                      #include <QStandardPaths>
                      #include <QClipboard>
                      #include <QGuiApplication>
                      
                      DemoWidget::DemoWidget(QWidget *parent)
                          : QWidget(parent)
                          , m_textEdit(nullptr)
                          , m_selectedEdit(nullptr)
                          , m_process(nullptr)
                      {
                          m_textEdit = new QTextEdit(this);
                          m_textEdit->setLineWrapMode(QTextEdit::NoWrap);
                          m_textEdit->setAcceptRichText(false);
                          m_textEdit->setReadOnly(true);
                          connect(m_textEdit, &QTextEdit::selectionChanged, this, &DemoWidget::handleSelection);
                      
                          m_selectedEdit = new QTextEdit(this);
                          m_selectedEdit->setLineWrapMode(QTextEdit::NoWrap);
                          m_selectedEdit->setAcceptRichText(false);
                          m_selectedEdit->setReadOnly(true);
                      
                          QVBoxLayout *layout = new QVBoxLayout(this);
                          layout->addWidget(m_textEdit);
                          layout->setStretchFactor(m_textEdit, 4);
                          layout->addWidget(m_selectedEdit);
                          layout->setStretchFactor(m_selectedEdit, 1);
                      
                          resize(1024, 768);
                      
                          QTimer::singleShot(1000, this, &DemoWidget::startProcess);
                      }
                      
                      DemoWidget::~DemoWidget()
                      {
                      }
                      
                      void DemoWidget::startProcess()
                      {
                          m_process = new QProcess(this);
                          connect(m_process, &QProcess::readyReadStandardOutput, this, &DemoWidget::handleOutput);
                          connect(m_process, &QProcess::finished, this, &DemoWidget::finishedOutput);
                      
                          QStringList args = QStringList() << "-l" << QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0);
                          m_process->start("/usr/bin/ls", args);
                      }
                      
                      void DemoWidget::handleOutput()
                      {
                          QByteArray processOutput = m_process->readAllStandardOutput();
                          m_textEdit->append(QString::fromUtf8(processOutput));
                      }
                      
                      void DemoWidget::finishedOutput()
                      {
                          m_textEdit->append(QStringLiteral("\n\n=====\nFinished"));
                      }
                      
                      void DemoWidget::handleSelection()
                      {
                          // will work on Linux only, rough demo only
                          QClipboard *clipboard = QGuiApplication::clipboard();
                          m_selectedEdit->setPlainText(clipboard->text(QClipboard::Selection));
                      }
                      
                      

                      No intervening xterm, no separate processes rendering into a Qt window, no problem accessing the text in the edit. This is a way to address what you are trying to do, but what you are trying to do is probably not the best solution to your actual problem... you could not make QBluetooth work.

                      This post proudly sponsored by XY Problem

                      A Offline
                      A Offline
                      Anonymous_Banned275
                      wrote on last edited by
                      #14

                      @ChrisW67 said in how to capture bluetooth command text selection running in QProcess ?:

                      Chis
                      I have your code partially inserted in my project.

                      Since your code runs the QProcess I have to bypass my "run QProcess" or add your code to existing MDI child.

                      So far it looks as it will process the text - the task is still to "drag and drop" the selected text between MDI subwindows .

                      I will tackle the graphics after I get this resolved - using QClipboard mode.

                      PS
                      I have explained (several times) I like to "drag and drop" using xterm/ bluetoothctl GUI - NOT just bluetoothctl text.
                      I had that - just text - working long time ago.

                      I am NOT changing my task / goal just because.....

                      There is no relationship between the QTextEdit, or whatever else you put in the QMdiSubWindow, and the separate operating system process you start (xterm) other than that you have directed that process to render its output on the screen in the same location as the QMdiSubWindow.

                      There is no relationship between the input/output streams of the xterm you have launched with QProcess and the input/output streams of the process or processes being run internally by xterm. So, for example, xterm does not send anything to standard out when it is asked, as you do, to execute bluetoothctl inside even though bluetoothctl does output (see example below).
                      2b8a687a-d46c-4889-b4a3-40d36d55dd56-image.png
                      You therefore cannot access the bluetoothctl output through the QProcess instance.

                      Here is a complete example widget that captures the output into a QTextEdit and can see the selections/clipboard.

                      #ifndef DEMOWIDGET_H
                      #define DEMOWIDGET_H
                      
                      #include <QWidget>
                      #include <QTextEdit>
                      #include <QProcess>
                      
                      class DemoWidget : public QWidget
                      {
                          Q_OBJECT
                      
                      public:
                          DemoWidget(QWidget *parent = nullptr);
                          ~DemoWidget();
                      
                      private slots:
                          void startProcess();
                          void handleOutput();
                          void finishedOutput();
                          void handleSelection();
                      
                      private:
                          QTextEdit *m_textEdit;
                          QTextEdit *m_selectedEdit;
                          QProcess *m_process;
                          QByteArray buffer;
                      };
                      #endif // DEMOWIDGET_H
                      
                      #include "demowidget.h"
                      
                      #include <QVBoxLayout>
                      #include <QTimer>
                      #include <QStandardPaths>
                      #include <QClipboard>
                      #include <QGuiApplication>
                      
                      DemoWidget::DemoWidget(QWidget *parent)
                          : QWidget(parent)
                          , m_textEdit(nullptr)
                          , m_selectedEdit(nullptr)
                          , m_process(nullptr)
                      {
                          m_textEdit = new QTextEdit(this);
                          m_textEdit->setLineWrapMode(QTextEdit::NoWrap);
                          m_textEdit->setAcceptRichText(false);
                          m_textEdit->setReadOnly(true);
                          connect(m_textEdit, &QTextEdit::selectionChanged, this, &DemoWidget::handleSelection);
                      
                          m_selectedEdit = new QTextEdit(this);
                          m_selectedEdit->setLineWrapMode(QTextEdit::NoWrap);
                          m_selectedEdit->setAcceptRichText(false);
                          m_selectedEdit->setReadOnly(true);
                      
                          QVBoxLayout *layout = new QVBoxLayout(this);
                          layout->addWidget(m_textEdit);
                          layout->setStretchFactor(m_textEdit, 4);
                          layout->addWidget(m_selectedEdit);
                          layout->setStretchFactor(m_selectedEdit, 1);
                      
                          resize(1024, 768);
                      
                          QTimer::singleShot(1000, this, &DemoWidget::startProcess);
                      }
                      
                      DemoWidget::~DemoWidget()
                      {
                      }
                      
                      void DemoWidget::startProcess()
                      {
                          m_process = new QProcess(this);
                          connect(m_process, &QProcess::readyReadStandardOutput, this, &DemoWidget::handleOutput);
                          connect(m_process, &QProcess::finished, this, &DemoWidget::finishedOutput);
                      
                          QStringList args = QStringList() << "-l" << QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0);
                          m_process->start("/usr/bin/ls", args);
                      }
                      
                      void DemoWidget::handleOutput()
                      {
                          QByteArray processOutput = m_process->readAllStandardOutput();
                          m_textEdit->append(QString::fromUtf8(processOutput));
                      }
                      
                      void DemoWidget::finishedOutput()
                      {
                          m_textEdit->append(QStringLiteral("\n\n=====\nFinished"));
                      }
                      
                      void DemoWidget::handleSelection()
                      {
                          // will work on Linux only, rough demo only
                          QClipboard *clipboard = QGuiApplication::clipboard();
                          m_selectedEdit->setPlainText(clipboard->text(QClipboard::Selection));
                      }
                      
                      

                      No intervening xterm, no separate processes rendering into a Qt window, no problem accessing the text in the edit. This is a way to address what you are trying to do, but what you are trying to do is probably not the best solution to your actual problem... you could not make QBluetooth work.

                      This post proudly sponsored by XY Problem

                      Christian EhrlicherC JonBJ 2 Replies Last reply
                      0
                      • A Anonymous_Banned275

                        @ChrisW67 said in how to capture bluetooth command text selection running in QProcess ?:

                        Chis
                        I have your code partially inserted in my project.

                        Since your code runs the QProcess I have to bypass my "run QProcess" or add your code to existing MDI child.

                        So far it looks as it will process the text - the task is still to "drag and drop" the selected text between MDI subwindows .

                        I will tackle the graphics after I get this resolved - using QClipboard mode.

                        PS
                        I have explained (several times) I like to "drag and drop" using xterm/ bluetoothctl GUI - NOT just bluetoothctl text.
                        I had that - just text - working long time ago.

                        I am NOT changing my task / goal just because.....

                        There is no relationship between the QTextEdit, or whatever else you put in the QMdiSubWindow, and the separate operating system process you start (xterm) other than that you have directed that process to render its output on the screen in the same location as the QMdiSubWindow.

                        There is no relationship between the input/output streams of the xterm you have launched with QProcess and the input/output streams of the process or processes being run internally by xterm. So, for example, xterm does not send anything to standard out when it is asked, as you do, to execute bluetoothctl inside even though bluetoothctl does output (see example below).
                        2b8a687a-d46c-4889-b4a3-40d36d55dd56-image.png
                        You therefore cannot access the bluetoothctl output through the QProcess instance.

                        Here is a complete example widget that captures the output into a QTextEdit and can see the selections/clipboard.

                        #ifndef DEMOWIDGET_H
                        #define DEMOWIDGET_H
                        
                        #include <QWidget>
                        #include <QTextEdit>
                        #include <QProcess>
                        
                        class DemoWidget : public QWidget
                        {
                            Q_OBJECT
                        
                        public:
                            DemoWidget(QWidget *parent = nullptr);
                            ~DemoWidget();
                        
                        private slots:
                            void startProcess();
                            void handleOutput();
                            void finishedOutput();
                            void handleSelection();
                        
                        private:
                            QTextEdit *m_textEdit;
                            QTextEdit *m_selectedEdit;
                            QProcess *m_process;
                            QByteArray buffer;
                        };
                        #endif // DEMOWIDGET_H
                        
                        #include "demowidget.h"
                        
                        #include <QVBoxLayout>
                        #include <QTimer>
                        #include <QStandardPaths>
                        #include <QClipboard>
                        #include <QGuiApplication>
                        
                        DemoWidget::DemoWidget(QWidget *parent)
                            : QWidget(parent)
                            , m_textEdit(nullptr)
                            , m_selectedEdit(nullptr)
                            , m_process(nullptr)
                        {
                            m_textEdit = new QTextEdit(this);
                            m_textEdit->setLineWrapMode(QTextEdit::NoWrap);
                            m_textEdit->setAcceptRichText(false);
                            m_textEdit->setReadOnly(true);
                            connect(m_textEdit, &QTextEdit::selectionChanged, this, &DemoWidget::handleSelection);
                        
                            m_selectedEdit = new QTextEdit(this);
                            m_selectedEdit->setLineWrapMode(QTextEdit::NoWrap);
                            m_selectedEdit->setAcceptRichText(false);
                            m_selectedEdit->setReadOnly(true);
                        
                            QVBoxLayout *layout = new QVBoxLayout(this);
                            layout->addWidget(m_textEdit);
                            layout->setStretchFactor(m_textEdit, 4);
                            layout->addWidget(m_selectedEdit);
                            layout->setStretchFactor(m_selectedEdit, 1);
                        
                            resize(1024, 768);
                        
                            QTimer::singleShot(1000, this, &DemoWidget::startProcess);
                        }
                        
                        DemoWidget::~DemoWidget()
                        {
                        }
                        
                        void DemoWidget::startProcess()
                        {
                            m_process = new QProcess(this);
                            connect(m_process, &QProcess::readyReadStandardOutput, this, &DemoWidget::handleOutput);
                            connect(m_process, &QProcess::finished, this, &DemoWidget::finishedOutput);
                        
                            QStringList args = QStringList() << "-l" << QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0);
                            m_process->start("/usr/bin/ls", args);
                        }
                        
                        void DemoWidget::handleOutput()
                        {
                            QByteArray processOutput = m_process->readAllStandardOutput();
                            m_textEdit->append(QString::fromUtf8(processOutput));
                        }
                        
                        void DemoWidget::finishedOutput()
                        {
                            m_textEdit->append(QStringLiteral("\n\n=====\nFinished"));
                        }
                        
                        void DemoWidget::handleSelection()
                        {
                            // will work on Linux only, rough demo only
                            QClipboard *clipboard = QGuiApplication::clipboard();
                            m_selectedEdit->setPlainText(clipboard->text(QClipboard::Selection));
                        }
                        
                        

                        No intervening xterm, no separate processes rendering into a Qt window, no problem accessing the text in the edit. This is a way to address what you are trying to do, but what you are trying to do is probably not the best solution to your actual problem... you could not make QBluetooth work.

                        This post proudly sponsored by XY Problem

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #15

                        @AnneRanch said in how to capture bluetooth command text selection running in QProcess ?:

                        I have explained (several times) I like to "drag and drop" using xterm/ bluetoothctl GUI - NOT just bluetoothctl text.

                        And we told you that this does not work when the external process doesn't support it.

                        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
                        • C Offline
                          C Offline
                          ChrisW67
                          wrote on last edited by
                          #16

                          @JonB I know. You can lead a horse to water but you cannot make it drink.

                          1 Reply Last reply
                          1
                          • A Anonymous_Banned275

                            @ChrisW67 said in how to capture bluetooth command text selection running in QProcess ?:

                            Chis
                            I have your code partially inserted in my project.

                            Since your code runs the QProcess I have to bypass my "run QProcess" or add your code to existing MDI child.

                            So far it looks as it will process the text - the task is still to "drag and drop" the selected text between MDI subwindows .

                            I will tackle the graphics after I get this resolved - using QClipboard mode.

                            PS
                            I have explained (several times) I like to "drag and drop" using xterm/ bluetoothctl GUI - NOT just bluetoothctl text.
                            I had that - just text - working long time ago.

                            I am NOT changing my task / goal just because.....

                            There is no relationship between the QTextEdit, or whatever else you put in the QMdiSubWindow, and the separate operating system process you start (xterm) other than that you have directed that process to render its output on the screen in the same location as the QMdiSubWindow.

                            There is no relationship between the input/output streams of the xterm you have launched with QProcess and the input/output streams of the process or processes being run internally by xterm. So, for example, xterm does not send anything to standard out when it is asked, as you do, to execute bluetoothctl inside even though bluetoothctl does output (see example below).
                            2b8a687a-d46c-4889-b4a3-40d36d55dd56-image.png
                            You therefore cannot access the bluetoothctl output through the QProcess instance.

                            Here is a complete example widget that captures the output into a QTextEdit and can see the selections/clipboard.

                            #ifndef DEMOWIDGET_H
                            #define DEMOWIDGET_H
                            
                            #include <QWidget>
                            #include <QTextEdit>
                            #include <QProcess>
                            
                            class DemoWidget : public QWidget
                            {
                                Q_OBJECT
                            
                            public:
                                DemoWidget(QWidget *parent = nullptr);
                                ~DemoWidget();
                            
                            private slots:
                                void startProcess();
                                void handleOutput();
                                void finishedOutput();
                                void handleSelection();
                            
                            private:
                                QTextEdit *m_textEdit;
                                QTextEdit *m_selectedEdit;
                                QProcess *m_process;
                                QByteArray buffer;
                            };
                            #endif // DEMOWIDGET_H
                            
                            #include "demowidget.h"
                            
                            #include <QVBoxLayout>
                            #include <QTimer>
                            #include <QStandardPaths>
                            #include <QClipboard>
                            #include <QGuiApplication>
                            
                            DemoWidget::DemoWidget(QWidget *parent)
                                : QWidget(parent)
                                , m_textEdit(nullptr)
                                , m_selectedEdit(nullptr)
                                , m_process(nullptr)
                            {
                                m_textEdit = new QTextEdit(this);
                                m_textEdit->setLineWrapMode(QTextEdit::NoWrap);
                                m_textEdit->setAcceptRichText(false);
                                m_textEdit->setReadOnly(true);
                                connect(m_textEdit, &QTextEdit::selectionChanged, this, &DemoWidget::handleSelection);
                            
                                m_selectedEdit = new QTextEdit(this);
                                m_selectedEdit->setLineWrapMode(QTextEdit::NoWrap);
                                m_selectedEdit->setAcceptRichText(false);
                                m_selectedEdit->setReadOnly(true);
                            
                                QVBoxLayout *layout = new QVBoxLayout(this);
                                layout->addWidget(m_textEdit);
                                layout->setStretchFactor(m_textEdit, 4);
                                layout->addWidget(m_selectedEdit);
                                layout->setStretchFactor(m_selectedEdit, 1);
                            
                                resize(1024, 768);
                            
                                QTimer::singleShot(1000, this, &DemoWidget::startProcess);
                            }
                            
                            DemoWidget::~DemoWidget()
                            {
                            }
                            
                            void DemoWidget::startProcess()
                            {
                                m_process = new QProcess(this);
                                connect(m_process, &QProcess::readyReadStandardOutput, this, &DemoWidget::handleOutput);
                                connect(m_process, &QProcess::finished, this, &DemoWidget::finishedOutput);
                            
                                QStringList args = QStringList() << "-l" << QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0);
                                m_process->start("/usr/bin/ls", args);
                            }
                            
                            void DemoWidget::handleOutput()
                            {
                                QByteArray processOutput = m_process->readAllStandardOutput();
                                m_textEdit->append(QString::fromUtf8(processOutput));
                            }
                            
                            void DemoWidget::finishedOutput()
                            {
                                m_textEdit->append(QStringLiteral("\n\n=====\nFinished"));
                            }
                            
                            void DemoWidget::handleSelection()
                            {
                                // will work on Linux only, rough demo only
                                QClipboard *clipboard = QGuiApplication::clipboard();
                                m_selectedEdit->setPlainText(clipboard->text(QClipboard::Selection));
                            }
                            
                            

                            No intervening xterm, no separate processes rendering into a Qt window, no problem accessing the text in the edit. This is a way to address what you are trying to do, but what you are trying to do is probably not the best solution to your actual problem... you could not make QBluetooth work.

                            This post proudly sponsored by XY Problem

                            JonBJ Online
                            JonBJ Online
                            JonB
                            wrote on last edited by
                            #17

                            @AnneRanch said in how to capture bluetooth command text selection running in QProcess ?:

                            PS
                            I have explained (several times) I like to "drag and drop" using xterm/ bluetoothctl GUI - NOT just bluetoothctl text.
                            I had that - just text - working long time ago.
                            I am NOT changing my task / goal just because.....

                            I hear what you are saying. It's just that if you removed the xterm and did the bluetoothctl directly into a QTextEdit you would be able to easily do/recognise cut/copy/paste/drag/drop between that QTextEdit and your other windows in a way that won't be possible using xterm.

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              Anonymous_Banned275
                              wrote on last edited by
                              #18

                              UNTIL SOMEBODY BOTHERS TO READ And actually answers / elaborate on this thread original post - this is getting nowhere and very tiresome.

                              STUPID insults seldom lead to a solution... stop .

                              So ONE MORE TIME

                              What event / signal or whatever is generated when CLICKING ON SELECTED TEXT HIGHLIGHTS IT ?

                              Christian EhrlicherC C 2 Replies Last reply
                              0
                              • A Anonymous_Banned275

                                UNTIL SOMEBODY BOTHERS TO READ And actually answers / elaborate on this thread original post - this is getting nowhere and very tiresome.

                                STUPID insults seldom lead to a solution... stop .

                                So ONE MORE TIME

                                What event / signal or whatever is generated when CLICKING ON SELECTED TEXT HIGHLIGHTS IT ?

                                Christian EhrlicherC Offline
                                Christian EhrlicherC Offline
                                Christian Ehrlicher
                                Lifetime Qt Champion
                                wrote on last edited by
                                #19

                                @AnneRanch said in how to capture bluetooth command text selection running in QProcess ?:

                                What event / signal or whatever is generated when CLICKING ON SELECTED TEXT HIGHLIGHTS IT ?

                                None in your application.

                                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
                                2
                                • A Anonymous_Banned275

                                  UNTIL SOMEBODY BOTHERS TO READ And actually answers / elaborate on this thread original post - this is getting nowhere and very tiresome.

                                  STUPID insults seldom lead to a solution... stop .

                                  So ONE MORE TIME

                                  What event / signal or whatever is generated when CLICKING ON SELECTED TEXT HIGHLIGHTS IT ?

                                  C Offline
                                  C Offline
                                  ChrisW67
                                  wrote on last edited by
                                  #20

                                  @AnneRanch said in how to capture bluetooth command text selection running in QProcess ?:

                                  What event / signal or whatever is generated when CLICKING ON SELECTED TEXT HIGHLIGHTS IT ?

                                  Or, if you remove xterm as an intermediary, you can get the text in a Qt environment and receive QTextEdit::selectionChanged() and QTextEdit::copyAvailable() signals. This is demonstrated in my example widget.

                                  1 Reply Last reply
                                  1

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved