|
Pretty good assumptions, I believe.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Richard MacCutchan wrote: If the object is NULL, then you skip to line 14
The OP shows the posted output. For example the following line.
" Sucess Found textEdit "
So line 5 is being executed (and the other lines in that block by the rest of the output.)
Of course the code is still wrong if the null pointer does show up.
Richard MacCutchan wrote: the debug output you have shown above does not match that code
Perhaps that is the actual problem. They think they are running the code shown but the code being executed is different. I have had that happen to me. Often enough that I probably do compiles, cleans and builds far more often than is needed.
|
|
|
|
|
jschell wrote: Perhaps that is the actual problem. They think they are running the code shown but the code being executed is different. Given who I suspect is asking the question I am not at all surprised.
And if you look at OP's reply to Dave Kreskowiak you will see more confusion.
|
|
|
|
|
I am trying to extract MAC address from text, and it is failing.
Here is the debug print of the "inString" text to extract the MAC from :
"Inquiring ...\n\t98:D3:31:F8:39:33\tclock offset: 0x7c6b\tclass: 0x001f00\n"
Here is my temporary code with regular expression which must be in error, but I do not see it.
QRegularExpression re(" [^\x00-\x7F]+\\ *(?:[^\x00-\x7F]| )*");
QRegularExpressionMatch match = re.match(inString);
if (match.hasMatch()) {
text = " Has match ";
QStringList result = match.capturedTexts();
text += result.at(0);
}
else
{
text = " NO match found ";
}
qDebug() << text;
Here is "run time error " , I am not sure why " invalid object" .
Does it mean my regular expression is incorrect ?
QRegularExpressionPrivate::doMatch(): called on an invalid QRegularExpression object
" NO match found "
If additional info would help, please ask.
Help analyzing the expression would be also greatly appreciated.
Thanks
|
|
|
|
|
You can validate your regex at any number of sites that do that sort of thing. That would help you determine if the problem is the regex itself, or the QRegularExpression object.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I can see one thing wrong with the expression right off the bat.
You're trying to match hexadecimal characters from 00 to FF, but the range you specify is only 00 to 7F.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Yes, I found that error too. It still fails. I am going t0 verify the expression using on one of the test sites...
|
|
|
|
|
Mrs Google found this
Regex.ai - Artificial Intelligence Regular Expression Generator[^]
Now for questions :
It is unclear how to select multiple entries from the text AKA highlight singe entry works ,
now to to select another part - dedicated by bold ?
Bold text
Devices:\n\thci0\t00:15:83:15:A2:CB\n
For old fart the text is too small - is there a way to make it bigger or do I have to tell Ubuntu ?
|
|
|
|
|
Another option would be something like:
int pos1 = index of first \t in inString;
int pos2 = index of second \t in inString;
int length = pos2 - pos1;
string MAC = inString.substring(pos1, length);
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Yes, this just proves there is more than one way to skin a cat...
I did checked two AI regular expression generators and they came up with two solutions..
One pretty goofy.
My current preference to match MAC address is :
([0-F]{2}[:]){5}[0-F]{2})
it "finds" the address, but also finds a single two character in it.
The interesting part , the [0-F] apparently searches for characters between ASCII O and F - it does not search for digits. ( My opinion)
|
|
|
|
|
The range [0-F] includes the characters :;<=>@ , and does not include lowercase letetrs. You're better off either with [0-9a-fA-F] . Alternatively, if your regex engine has character classes then you could use ([[:xdigit:]]{2}[:]){5}[[:xdigit:]]{2} I'm not sure you need to specify the colon as a match set, unless regex treats them as special characters.
Keep Calm and Carry On
|
|
|
|
|
Thanks, as long as the entry is characters , not numbers, it makes sense.
Since the MAC address "hex numbers" is capitals I do not need [a-f ].
You have a good point - I'll try to delete [:] - in theory it should work.
|
|
|
|
|
Salvatore Terress wrote: Thanks, as long as the entry is characters , not numbers, it makes sense.
Why would they not be characters? You seem to be reading input from another command, so it should always be characters.
Salvatore Terress wrote: Since the MAC address "hex numbers" is capitals I do not need [a-f ].
That depends. Can you guarantee that you'll always get upper case hex digits? Under linux, the arp commands uses lower case letters for the MAC address. Others might as well
Salvatore Terress wrote: You have a good point - I'll try to delete [:] - in theory it should work.
It should. But as noted above, it would depend on where you're getting your input from. Under Windows, if you run ipconfig /all you get the Mac address separated by dashes e.g. "00-4B-35-30-35-34", so you may need to allow for that too.
Keep Calm and Carry On
|
|
|
|
|
Salvatore Terress wrote: ([0-F]{2}[:]){5}[0-F]{2}) Should be:
([0-F]{2}[:]){5}[0-F]{2}
modified 25-Oct-23 2:01am.
|
|
|
|
|
Google seems to return regular expressions to validate a mac address. Not to mention explaining forms that might be less than obvious.
mac address regular expression
Other than that the square brackets are used for character matching. Single character. Best I can tell you seem to be trying to match a sequence of characters (2 digit hex.)
|
|
|
|
|
What is a correct way to pass parameter / variable to function ?
The attached snippet writes text to the GUI object and it is done in object constructor.
My task is to pass ui->textEdit_2 to object function so it can be processed OUTSIDE constructor
ui->setupUi(this);
text = "Constructor ";
ui->textEdit_2->append(text);
text = " Initialize DEBUG trace ";
ui->textEdit_2->append(text);
private:
public:
Ui::MainWindow_C_CODE_FORM *ui;
Here is my test function declaration:
QString ShowText(QString text, QTextEdit *textEDIT );
I have tried several ways to access the function, but I am obviously "doing it wrong".
PS
I you cannot help "as is " , please, do not complain - it would work better
if you ask what is missing instead.
Thank you very much .
|
|
|
|
|
Please supply the types of your objects, a sample of how you are calling ShowText() and an explanation of why you thing you're "doing it wrong". Do you get compilation errors or warnings? Does the program crash, or do something unexpected? Does the fan in the bedroom turn on? You're not telling us, and most of us will refuse to speculate.
Keep Calm and Carry On
|
|
|
|
|
Something like
void ShowText(QString text, QTextEdit * pTextEdit)
{
pTextEdit->append(text);
} called this way:
text = "Foo";
ShowText(text, ui->text_edit2);
could work.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
Thanks, I have it working calling the function within constrictor.
Appreciate your help getting this part fixed.
I am trying to call it from another part of the code and getting this error
/mnt/RAID_124/BT/BT_Oct20_BASE_/mdi/mainwindow.cpp:1274:
error: member access into incomplete type 'Ui::MainWindow_C_CODE_FORM'
mainwindow.cpp:1274:32: error: member access into incomplete type
'Ui::MainWindow_C_CODE_FORM'
ShowText(text,MWCCF->ui->textEdit());
^
../CCC_SOURCE/Bluetoothctl/../C_CODE_FORM/mainwindow_c_code_form.h:42:22: note: forward declaration of 'Ui::MainWindow_C_CODE_FORM'
namespace Ui { class MainWindow_C_CODE_FORM; }
^
I could use some help to solve this.
PS
This gives same error
ShowText(text,MWCCF->ui->textEdit);
Thanks
|
|
|
|
|
SOLVED ??
This is silly , but it works
text = " START DEBUG trace " ;
finds first QTextEdit
QTextEdit *textEditPtr = MWCCF->centralWidget()->findChild<QTextEdit *>();
or pass desired widget name (?)
QTextEdit *textEditPtr = MWCCF->centralWidget()->findChild<QTextEdit *>("textEdit");
if (textEditPtr)
{
qDebug("Found textEdit ");
textEditPtr->append(text);
}
else
qDebug() << "Did not find any QTextEdit";
|
|
|
|
|
Salvatore Terress wrote: I you cannot help "as is " , please, do not complain - it would work better Statements such as this are unnecessary, and make us suspect that you are a sock puppet for a certain member who was previously banned for abuse.
|
|
|
|
|
SOLVED
As suspected , passing parameters to object was incomplete and incorrect.
Many thanks for all support received.
modified 19-Oct-23 14:11pm.
|
|
|
|
|
It is not clear, but I suspect the compiler has optimized it to something like:
MainWindow_C_CODE_FORM *MWCCF_List = new MainWindow_C_CODE_FORM(nullptr, (QStringList){ " Process basic hcitool commands "," I/O hcitool "," DEBUG Trace " });
assuming that QSL is not used anywhere else.
|
|
|
|
|
Warning messages out of context are not very helpful. We don't know for at fact that the messages you provided to us are anything to do with the supplied code.
IMHO it seems highly unlikely that the value being optimized out is responsible for the possible memory leak. If the compiler can reason that it can optimize away a variable, it should know that no memory clean up is needed. But cleanup may be part of the the expected tasks of the programmer, and adding it in (if needed) might remove both warnings.
Start by fixing the issue you have passing the QWidget correctly. There's no telling what doing it wrong might be doing internally. It sounds like a recipe for invoking undefined behavior.
If the warnings persist after fixing the calling issue, then start by turning off optimization. If you're on Linux, you might also make sure that you're including debug symbols (-g flag). Depending on what "the tool" is, adding in debugging symbols might help narrow down the origin of the memory leak. Consult the documentation for your IDE (QT Creator?) on how you go about setting the optimization level, and turning on inclusion of debug symbols in the executable.
Keep Calm and Carry On
|
|
|
|
|
This is just an educated guess on my part, and I'm not a C/C++ expert by any means.
Maybe the compiler is telling you that it's discarding the copy of the QStringList that is being created when you pass by value.
(Especially since the value is not being used inside the function, I think the compiler might be optimising it away and letting you know.)
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|