I have an instance of QClipboard and I want to shift data to it whenever user clicks somewhere in the Application. It seems like there are sometimes performance issues with QClipboard which causes the application to freeze because data gets put on OS clipboard of linux.
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(QString("Glorious Text"), QClipboard::Clipboard);
It does not happen every time but every fifth or sixth click it freezes for some seconds. So I can not really reproduce properly.
https://www.medo64.com/2019/12/copy-to-clipboard-in-qt/ solved it for me.
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(text, QClipboard::Clipboard);
if (clipboard->supportsSelection()) {
clipboard->setText(text, QClipboard::Selection);
}
#if defined(Q_OS_LINUX)
QThread::msleep(1); //workaround for copied text not being available...
#endif
Related
C# Winform Visual Studio Application hangs with "Not Responding" after some hours of use and Windows pop-up appears closing application. This often occurs when initiating a remote desktop to the computer or bringing the application window to focus after minimising.
The application consumes full CPU when bringing to focus and gets progressively sluggish in this process.
The windows form is multithreaded GUI for controlling a device via RS232. It uses a textbox for a debug output several times a second. Writing to the textbox is done with an Asynchronous method.
void asyncAppendTextBox(TextBox tb, string str)
{
if (IsHandleCreated)
{
tb.BeginInvoke(
new Action(() =>
{
tb.AppendText(str + appLifetimeSW.ElapsedMilliseconds.ToString());
}
));
}
}
The answer to this problem was fairly simple in the end. The Textbox was simply getting too full of text and eventually taking >minutes to repaint everything when bringing back to focus. This eluded me at first because the textbox was painting no problem with the AppendText() function. After some hours of the program running, the amount of text was effectively appearing to hang the application (according to Windows).
The simple fix was to write to a string array instead and set the text in the text box via 'Textbox.SetText(string[])' in the asynchronous invoke method.
I additionally shift the array by one and write to the last element of the array to match the appearance of AppendText().
No more hanging and application is responsive.
I have a timer set on my application using html 5 and jquery. Now when I move on to different tab or I minimize my window, the timer for that few seconds stops. I do not want this. And again as I open the window(tab or browser page, whatever u say)the timer starts. But it gets pause for those seconds. What should be the issue ? What code should I write for it ?
I want that even though I minimize my window or look at new tab, my timer should be on.
Code for getting the timer is:
Here the timer is set and it runs, but as soon as i move my focus to other page, the timer is paused. A function is just shown here.
function showTime()
{
if(ms>=100){
ms = 0;
s++;
}
// calculates seconds and hours also
var temp= $("#clock").text(checkTime(h)+":"+checkTime(m)+":"+checkTime(s)+"."+checkTime(ms));
if(windows_focus=true){
timer=setTimeout('showTime()', 10);}
else if(windows_focus=false){
timer=setTimeout('showTime()', 100);
}
}
checktime is a function which just add a zero in front of numbers<10.
I just added in windows_focus=false also, as I thought if I move away, then also it should work, but i am not getting.
I tried using setInterval also, when I use setInterval, then even though I minimize the window the timer is getting started. But the problem is that the time runs in a really weird manner. Runs very very fast.
Can anyone please help me out.
http://jsfiddle.net/JWxS6/44/ this might be useful to see my code.
I am really new, please help me out
I want to make Application where you can see only one window at a time in order to save memory. Let's say, we have one window, after pressing a button another window shows, but the previous is deleted. If the button pressing is handled in window callback function, is it safe to delete the window from inside of that window function and recreate it after the new window is closed? Something like that:
void callback(...) {
...
if (msgID == ENTER_KEY) {
deleteMyself();
showWindow2();
createMyself();
}
...
}
Could you suggest better approach if this one is not good?
I think this is generally on a desktop a bad idea. So you would loose everything the userinput. And depending on your application the user maybe confuses why an options dialog closes the main window.
However on a mobile device it is normal only to have just one window (except you use dialogs). But in those cases all inputs should be stored so that the window can be reovered to its old state.
In general if you have trouble with the memory managment better check if you leak somewhere memory in most cases the GUI does not need so much memory.
I have an app, where I generate text (about 500 characters), and I would like the user to have some means of copying that text for use outside of the application.
I don't want to use any capabilities for this app (like web, or contacts).
Here's what I've tried (and why it's failed)
TextBox. IsReadOnly = true; SelectAll();
Can't SelectAll a read only text box
Turn off read only, hide the SIP
Can't hide the SIP on a (non-read-only) TextBox that the user is interacting with (I want to enable the user to copy, so needs to interact with the control)
allow edits, show sip, SelectAll()
The "copy" icon doesn't appear unless the user chose to select text
On selection changed (actually changed), SelectAll()
The "copy" icon doesn't appear unless the user selected the text? The copy icon appears erratically, nothing I would call an acceptable user experience.
So at this point, I'm quite far from what I want in a user experience, and I still don't have anything that works. Any suggestions?
Some other possible ways to answer my question include:
"How do I force the copy button to appear above text I programatically selected?"
"How do I change the selection behavior of a tap in a text box?"
Afaik there are some limitations to the Windows Phone 7 Clipboard:
Works only in TextBox and can only copy text upon users wish
Text is only kept until device gets locked. If your device gets locked, the clipboard will be wiped clean
Even if you try Clipboard.SetText Method, you will notice the SecurityException if you call this method without the users interaction. This is to keep the users data under control so that no rogue app can copy unrecognized Text.
But you could try Matt Laceys WP7Clipboard. It saves the clipboard content inside an image and can even copy bitmaps.
Try restyling the textbox as per http://mobileworld.appamundi.com/blogs/peterfoot/archive/2011/02/08/copyable-textblock-for-windows-phone.aspx
Here's what I eventually got mostly working
private void Export(StackPanel stacker)
{
var exportHeader = new TextBlock();
exportHeader.Text = "Export";
stacker.Children.Add(exportHeader);
var exportBox = new TextBox();
stacker.Children.Add(exportBox);
//exportBox.IsReadOnly = true; // hides SIP, but causes an exception with SelectAll() (pre-Mango, I haven't tried on Mango yet)
exportBox.FontSize = 1;
exportBox.Text = textToExport;
exportBox.GotFocus += new System.Windows.RoutedEventHandler((send, ev) =>
{
((TextBox)send).SelectAll();
});
exportBox.Focus();
}
Apparently, making the font size 1 makes the difference here, maybe because all of the text can appear on the screen at once? Who knows.
I accepted this answer, because no one else posted a better solution. I would appreciate a better solution. If you can get the SIP to go away, that would be awesome.
I really enjoy using RBSplitView, an open source replacement for NSSplitView, but I have a problem in my shipping app and am experiencing it again in a new project.
The problem is I'm telling the RBSplitView to autosave its position state by giving it an autosave name. When my app launches the RBSplitView doesn't seem to honor the saved state till a second after the window is drawn.
I've spent the night trying to debug the behavior but have had little success. Anyone out there use this lib and have some advice?
You can scrub this quicktime movie to the issue at work:
http://media.clickablebliss.com/billable/interface_experiments/rbsplitview_delayed_autosave_reload2.mov
I've still been unable to figure out why this is happening but I do have a workaround.
First, make sure your main window is not visible at launch and then at the end of applicationDidFinishLaunching in your app delegate add something like:
[mainWindow performSelector:#selector(makeKeyAndOrderFront:) withObject:self afterDelay: 0.1];
The delay is the key. If you just tell the window to makeKeyAndOrderFront: I still see the issue. However as long as it has a beat of time it looks good.
This likely is happening because the RBSplitView instance needs to wait until it's first moment to get to set its frame to the autosaved value, which happens to be after the user can see it. This 0.0-delay trick simply delays showing the window until the very next runloop, which gives the split view a chance to do its magic (and other views) so that when the user sees the window, it's already nice and sexy. So just do the delay at 0.0 and you'll be fine.
I have a similar, but slightly different workaround in my app that uses RBSplitView. In applicationDidFinishLaunching:, I call adjustSubviews on the split view before calling makeKeyAndOrderFront: on the window that contains it. This seems to knock the split view in to order before it gets displayed on the screen.