I am using a QTextEdit in my C++ GUI application, I use textEdit->append(byteArray); to add some text, unfortunately append() adds a new line character at the end that I would like to remove after each call of append(). I know I could use insertPlainText() which does not add a new line character but it uses a lot more memory when dealing with big documents.
Thanks for your help!
Since the documentation for QTextEdit::insertPlainText says
It is equivalent to
edit->textCursor().insertText(text);
I would assume that you can just do something like
edit->textCursor().deletePreviousChar();
If you need to you can first clear any selection with
edit->textCursor().clearSelection();
Related
I'm quite new on Qt softw.
I would like to make a small program, for my internship.
I've made a textedit object for write a MAC Address (17 chars max so.).
I want that after writing 2 chars, when you write the third one, it automatically put a : before write the third char.
DC:R
^
so when you press R it puts before automatically the :.
I Hope I'm clear.
use QLineEdit instead of QTextEdit and use setInputMask function of QLineEdit to set a format;
setInputMask("HH:HH:HH:HH:HH:HH;_");
Take a look at here
As the title says, I am wondering how to delete a newline that is printed to the console, if it is possible.
I have seen the following:
How to delete a newline using \b
Except that is about using \b to delete a new line, and I would just like to know how to do it, using any possible method.
More specifically:
If I have
----
- -
----
printed to the console, I would like to know how to delete the last two lines, to have just ----.
Thanks in advance!
Note: I left out an OS to see if I can get an answer that would work on any OS.
As I know, there is no portable way to work with not only current line of output,
but with several lines on console.
So you need some kind of wrapper around suitable functionality in each OS,
the most portable library for this, as I know is:
http://pdcurses.sourceforge.net/
I need a little help with my calculator program. I have created the code for the main buttons like the numbers 0-9 and the arithmetic operators to make it perform simple calculations.
What I'm having problems with right now is making the CE button work, after clicking the CE button I need the last entered character to be removed from the display label.
I have tried to adapt this code somehow, but it doesn't work:
lblResult->substr(0, lblResult->size()-1);
I know I'm doing somehting wrong here, can you please help me?
Thanks in advance
...Now that we know that lblResult is a System.Windows.Forms.Label, we can look at the documentation.
A Label has a Text Property, which is a String^ (i.e. a string reference).
For what you want to do, the Remove Method of String is appropriate. But note in the documentation it says that it "Returns a new string in which a specified number of characters from the current string are deleted." This means that it does not modify the string, but returns a modified copy.
So to change the label's text, we need to assign to its Text property what we want: the current string with all of the characters except the last:
lblResult->Text = lblResult->Text->Remove(lblResult->Text->Length - 1);
lblResult->resize(lblResult->size() - 1);
In this case you can use components Remove and Length methods.
Use the following code to access the components text:
component->Text
Than remove the last character of string by accessing Remove and component Length method
= component->Text->Remove(component->Text->Length - 1)
I hope you find this useful.
Just asking the obvious -- the whole statement is
*lblResult = lblResult->substr(0, lblResult->size()-1);
right?
I am working on IDML files which are used by InDesign. I am facing a problem in inserting a special instruction. I need to embed RightIndentTab with IDML file. The unicode for the same is U+0008. When I try to add that it throws error as this unicode is not supported in XML specs.
I looked more into it and IDML has a special Processing Instruction which can be inserted it looks like now the problem is when I add this it introduces a line break before the RightIndent symbol. On debugging I found that the content element looks like
<Content>
<?ACE 8?>9731396</Content>
It is an XElement and I see \r\n when I call ToString() on it. I also tried using XmlWriter.
What I would like is an XElement object which looks like
<Content><?ACE 8?>9731396</Content>
Thanks in advanced!
I've encountered exactly the same problem adding processing instructions to IDML, using .NET. Even with significant whitespace turned off I got a line break that InDesign treats as part of the text.
The only solution I have found is to save the file as XML, then open it as a text document and use a regular expression to replace >\r\n<? with just ><?. It's ugly and kludgy, but it does work - I don't have the regex to hand but you should be able to figure it out fairly quickly.
I've never had any problems adding unicode chars to XML, though. I would just use and also set the XmlWriter encoding to use unicode. See here for an example: http://bytes.com/topic/net/answers/176665-how-write-unicode-using-xmlwriter which recommends:
XmlTextWriter myWriter = new XmlTextWriter( fileStream,
new System.Text.UnicodeEncoding( false, false) );
I'm writing a (Win32 Console) program that wraps another process; it takes parameters as in the following example:
runas.exe user notepad foo.txt
That is: runas parses user and then will run notepad, passing the remaining parameters.
My problem is that argv is broken down into individual parameters, but CreateProcessAsUser requires a single lpszCommandLine parameter.
Building this command line is probably not as simple as just joining argv back together with spaces. Any pointers?
This is just an example. My first argument isn't actually a user name, and might have spaces in it. This makes manually parsing the result of GetCommandLine tricky.
Similarly, a naive concatenation of argv won't work, because it needs to deal with the case where the original arguments were quoted and might have spaces in them.
Manually recombining them is hard:
You could try to re-combine them, I think it would work, but be sure to following the same command line escaping rules that windows has. This could be more than the trivial solution you're looking for.
Also if there are any parameters that have spaces in them, then you would want to join them to the string with quotes around them. Here is an example of a strange escaping rule: if you have --folderpath "c:\test\" then the last backslash has to be doubled --folderpath "c:\test\\".
If you are using MFC:
You can can get the value you want from your derived CWinApp's theApp.m_lpCmdLine. Note you could still access them the other way too with __argc, and __argv or CommandLineToArgvW.
If you are using Win32 only (even without a GUI):
You can get it from WinMain. Which can be your program's entry point.
Note you could still access them the other way too with __argc, and __argv or CommandLineToArgvW.
If you must use a console based application with main or wmain:
The Win32 API GetCommandLine seems to be the way to go. You would need to still parse this to get past the .exe name though. Take into account quotes around the exe name/path too. If there are no such quotes at the start, then just go to the next space for the start.
You can use the GetCommandLine function.
Why not use 'WinMain' instead of 'main'? This should give you the string in the format you want.
There is Win32 API call that returns command line: GetCommandLine
Provided you have a string allocated with enough space then use strcat on each item in the list. Yes, it is as simple as joining them back together with spaces.
Edit: Of course, you would need to enclose any items containing spaces within quotes.