我想确保我的类(更新程序服务)的所有方法都在 的线程内调用ExecutorService(假设甚至只有一个线程)。未给出方法的顺序,因此那些公共方法可能会从 的Executor线程和其他一些线程(主要是 GUI 线程)调用。
我的代码:
// Instantiated lazy using synchronized getter - I decided not to bother with shared locks
private ExecutorService executor;
/**
* Provides compatibility between calls from executor thread pool and other threads.
* No matter the thread from which you call this method, the callback will be executed
* within the loop. Proper events will be raised in the loop thread as well, so
* mind to use SwingUtilities.invokeLater if event …Run Code Online (Sandbox Code Playgroud) 我有这个功能来更新一些GUI的东西:
void SavedConnections::renderList()
{
// Do GUI stuff! Must run in Qt thread!!!
...
}
Run Code Online (Sandbox Code Playgroud)
我需要确保不从其他线程调用此函数.我打算做的是将它推迟到事件循环并发出警告:
void SavedConnections::renderList()
{
if(!this_thread_is_Qt_GUI_thread()) {
qDebug()<< "Warning: GUI operation attempted from non GUI thread!\n";
QCoreApplication::postEvent(this, new UpdateGUIEvent());
return;
}
// Do GUI stuff! Must run in Qt thread!!!
...
}
Run Code Online (Sandbox Code Playgroud)
这种模式也非常方便,可以保证在GUI线程中异步运行的方法没有任何丑陋的语法.我已经问过关于Java的ExecutorService的类似问题.
QString有一些路径:
QString path = "C:/bla/blah/x/y/file.xls";
Run Code Online (Sandbox Code Playgroud)
我认为可能获得最后一次补偿/将是一个良好的开端.然后我可以使用right方法(没有双关语)来获取该角色之后的所有内容:
path = path.right(path.lastIndexOf("/"));
Run Code Online (Sandbox Code Playgroud)
或者以更兼容的方式:
path = path.right(std::max(path.lastIndexOf("\\"), path.lastIndexOf("/")));
Run Code Online (Sandbox Code Playgroud)
两者都有相同的坏结果:
ah/x/y/file.xls
Run Code Online (Sandbox Code Playgroud)
这有什么不对?很明显,这条道路很快就被削减了,但它甚至更奇怪,它根本就没有削减/.
这是我发现的示例程序,它将允许您切换一些循环操作:
; This toggles the action
toggle:=false
F12::
; If true is assigned to toggle, loop starts
; It also can assign false even when loop is running
If (toggle := !toggle)
SetTimer, loop, -1
return
loop:
; Endless loop? Actually not, the value of toggle can be changed by
; another "thread" even when this loop is running
while toggle
{
Click
Sleep, 700
}
return
Run Code Online (Sandbox Code Playgroud)
现在我们可以看到有一些超时调用开始了无限循环。无限循环显然是同步的,没有回调或同步的块或任何东西。
尽管如此,按F12一下似乎可以正确停止循环,即使循环正在运行也是如此。
有人可以向我解释如何在autohotkey中执行线程吗?如何在没有竞争条件的情况下处理多个代码块?是否SetTimer调用在其中发挥什么作用?
我找到了将 ENUM 转换为驼峰大小写的解决方案,但它并不优雅。
var underscoreToCamelCase = function(str) {
str = (str === undefined || str === null) ? '' : str;
str = str.replace(/_/g, " ").toLowerCase();
return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match, index) {
if (+match === 0) return "";
return index == 0 ? match.toLowerCase() : match.toUpperCase();
});
}
Run Code Online (Sandbox Code Playgroud)
因此,如果 str 是 MY_ENUM_STRING,它将返回 myEnumString。
必须有一种方法可以通过单个正则表达式匹配来实现这一目标吗?
我允许自定义上下文菜单出现在表格上。这是菜单的生成方式,使用接受目标小部件和坐标的通用函数:
#include <QMenu>
void MainWindow::makeContextMenu(const QPoint& pos, QWidget* target)
{
QMenu *menu = new QMenu(this);
menu->addAction(new QAction("Action 1", menu));
menu->addAction(new QAction("Action 2", menu));
menu->addAction(new QAction("Action 3", menu));
// Notify window about clicking
QObject::connect(menu, &QMenu::triggered, this, &MainWindow::menuClicked);
// If this is a scroll area, map coordinates to real app coordinates
if(QAbstractScrollArea* area = dynamic_cast<QAbstractScrollArea*>(target))
menu->popup(area->viewport()->mapToGlobal(pos));
else
menu->popup(pos);
}
Run Code Online (Sandbox Code Playgroud)
问题是QMenu* menu永远不会被破坏并从内存中删除。MainWindow即使在它被隐藏之后,它仍然作为's child存在。
我该怎么办?我可以将菜单设置为删除自身吗?或者我应该重用相同的菜单实例还是将其保存到相同的指针中?
我正在尝试将一堆图像转换为视频。原始图像分辨率是 6000x4000,但是如果我使用 ffmpeg 创建具有该分辨率的视频,则没有播放器可以播放它,因为它太大了。
我尝试这样设置输出分辨率,将输入分辨率除以 4:
ffmpeg -r 60 -s 1500x1000 -start_number 3790 -i DSC_%04d.jpg -vcodec libx264 -crf 25 -pix_fmt yuv420p ../video_lowres.mp4
Run Code Online (Sandbox Code Playgroud)
这没有效果,但仍然生成 6000x4000 的视频。因此,我尝试了这个参数:scale=1500:1000我运行的完整命令:
ffmpeg -r 60 scale=1500:1000 -start_number 3790 -i DSC_%04d.jpg -vcodec libx264 -crf 25 -pix_fmt yuv420p ../video_lowres.mp4
Run Code Online (Sandbox Code Playgroud)
但我收到了这个错误:
[NULL @ 000002ad897bd9c0] Unable to find a suitable output format for 'scale=1500:1000'
scale=1500:1000: Invalid argument
Run Code Online (Sandbox Code Playgroud)
如何使用 ffmpeg 从照片创建缩小视频?
我正在寻找有关互联网浏览器历史的出版物.论文,文章,博客文章等等.在ACM IEEE等上找不到任何东西,我的博客搜索也没有发现任何显着的信息.
我正在尝试从C#中的字符串中提取域名.您不一定要使用RegEx,但我们应该能够yourdomain.com从以下所有内容中提取:
yourdomain.com
www.yourdomain.com
http://www.yourdomain.com
http://www.yourdomain.com/
store.yourdomain.com
http://store.yourdomain.com
whatever.youdomain.com
*.yourdomain.com
Run Code Online (Sandbox Code Playgroud)
此外,任何TLD是可以接受的,所以更换所有上述与.net,.org,'co'uk等.
我正在尝试使用Park-Miller-Carta PRNG随机数生成器的Java实现.
下面是在ActionScript 3的随机函数的实现从这里.
return (_currentSeed = (_currentSeed * 16807) % 2147483647) / 0x7FFFFFFF
+ 0.000000000233;
Run Code Online (Sandbox Code Playgroud)
我没有太多运气在Java中工作:
int seed = 20; //for example.
public double random() {
seed = (seed * 16807) % 2147483647;
return seed / 0x7FFFFFFF + 0.000000000233;
}
Run Code Online (Sandbox Code Playgroud)
这总是会回来的2.33E-10.我在Java中做错了什么想法?(AS3代码返回0.0001565276181885122,然后返回0.6307557630963248前两个带有种子的响应20).
qt ×3
c++ ×2
java ×2
regex ×2
asynchronous ×1
autohotkey ×1
browser ×1
c# ×1
ffmpeg ×1
javascript ×1
path ×1
qmenu ×1
qstring ×1
random ×1
string ×1