how to capture bluetooth command text selection running in QProcess ?
-
THIS IS A REPOST
i am still looking for help / C code assistance to resolve this.
The first attached picture show the result of this QProcess (test) code .
The key option is "into" which inserts the bluetootctl command result as MDI child.PLEASE note - these are an examples of QT , the actual bluetoothctl command results CANNOT be same after first usage.
Next picture show results of double click on the word - highlighting it.
processTERMINAL = new QProcess(); QString exec = "xterm" ; // terminal"; QStringList params; //#ifdef BYPASS params << "-T" << "bluetoothctl no options (interactive) case 1 -hold file " << "-fa" <<"Monospace" << "-fs" << "14"<< "-hold" << "-into" <<QString::number(winId())<< // "-geometry" <<"93x31+100+350" << // "-geometry" <<"200x200+1000+1000" << // xterm -fn 6x10 -geometry 80x24+30+200 & "-fn" <<"6x10"<< // "-geometry" <<"80x24+30+200 &" << // OK but in wrong location "-geometry" <<"80x24-0+0" << "-e" << "bluetoothctl | tee /tmp/temp.txt"; // temp execute here processTERMINAL->start(exec,params); if(processTERMINAL->waitForStarted()) { qDebug() << " DEBUG processTERMINAL->state() " << processTERMINAL->state(); QString output = processTERMINAL->readAllStandardOutput(); qDebug() <<" DEBUG output from processTERMINAL->readAllStandardOutput()\n "<< output;
I am unable to figure out HOW to pass the blutoothctl (MDI chilld) text selection BACK to QT .
(I did attempt to use "copy to clipboard " , but cannot find HOW to capture that either )What I know so far - it cannot be done via QProcess - BUT if it can be highlighted there MUST be a way to capture such event .
I be happy to provide more info....
-
@AnneRanch
When you usexterm
you cannot know or be notified when the user makes a selection there, nor directly access its content.Making a selection there should copy to clipboard, assuming you have default Ubuntu/GNOME settings.
There is no easy/automatic way to know this has happened. You can either:
-
Poll clipboard contents at frequent intervals.
-
Read e.g. Getting notified about clipboard content changes or Detect clipboard copy/paste event and modify clipboard contents and adapt the kind of code in https://github.com/cdown/clipnotify/blob/master/clipnotify.c to work from your Qt program.
UPDATE
QtQClipboard
has a dataChanged() signal, and even a selectionChanged() one. I do not know whether these would notify you about the change from the external application.However, in both these cases there is no way to know the copying has happened from the xterm process. The copy to clipboard may have happened from any process. All you will know is that its content has changed, from whatever source (e.g. even your own program).
-
-
@JonB ADDENDUM
I have "mouse move event " implemented in MDI child.
When I move the mouse to "the black window frame " the cursor located after bluethooocthl prompt highlights..I have other mouse events implemented but the code does not execute.
I am going to look into QClipbiard , sounds promising . THANKS
-
Another addendum - for discussion purpose.
I may have found PART of my problem)((s).
- If I remove the "info" options I get this:
That is definitely outside of main QT process. I have been calling it "OS window" .
- 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.
-
@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? -
@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.
-
@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.
-
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. -
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 byxterm
. So, for example,xterm
does not send anything to standard out when it is asked, as you do, to executebluetoothctl
inside even thoughbluetoothctl
does output (see example below).
You therefore cannot access thebluetoothctl
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
-
@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 thebluetoothctl
, capturing its input/output, removing the ANSI "color" control sequences it emits, and displaying its output in aQTextEdit.
It also shows a screenshot of what it looks like for a small exchange.
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 **
-
@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. -
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 . -
@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.
-
@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 byxterm
. So, for example,xterm
does not send anything to standard out when it is asked, as you do, to executebluetoothctl
inside even thoughbluetoothctl
does output (see example below).
You therefore cannot access thebluetoothctl
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
-
@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.
-
@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 aQTextEdit
you would be able to easily do/recognise cut/copy/paste/drag/drop between thatQTextEdit
and your other windows in a way that won't be possible using xterm. -
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 ?
-
@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.
-
@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.