如果我使用startDetached()启动QProcess,是否会获得完成的信号?我正在尝试启动一个进程,但是我需要能够在进程终止时获得一个事件.
我已经在Windows上使用Qt的商业版一段时间了,所以有大量的Visual Studio项目(vcproj文件).
我想开始将这些项目转移到Qt Creator中 - 我确实已经"手动"移动了其中的一些项目,并且可以使其工作 - 但似乎应该(可能是?)Visual Studio导入脚本或应用程序或某种能力.
是否有人知道这样的事情,或者一个可定义的程序来将项目从一个移动到另一个?
在我的应用程序中有主线程和工作线程(QThread).
从主线程我想调用我的工作线程的方法,让它在线程的上下文中运行.
我已经尝试使用QMetaObject::invokeMethod并给它QueuedConnection选项,但它不起作用.
我也尝试从主线程(连接到工作线程的插槽)发出信号,但也失败了.
这是我尝试的大致的片段:
class Worker : public QThread
{
Q_OBJECT
public:
Worker() { }
void run()
{
qDebug() << "new thread id " << QThread::currentThreadId();
exec();
}
public slots:
void doWork()
{
qDebug() << "executing thread id - " << QThread::currentThreadId();
}
};
Run Code Online (Sandbox Code Playgroud)
使用QMetaObject方式:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qDebug() << "main thread id - " << QThread::currentThreadId();
Worker worker;
worker.start();
QMetaObject::invokeMethod(&worker, "doWork", Qt::QueuedConnection);
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
使用信号方式: …
所以我有一个相当可观的程序,它偶尔会冻结。
该程序使用 Qt、开放场景图和谷歌日志记录。这种冻结发生在谷歌日志中的打印过程中。程序本身正在打印大量调试信息。我能够通过 gdb-server 连接到程序,这是堆栈跟踪:
#0 0x000000397ac0e030 in __write_nocancel () at ../sysdeps/unix/syscall-template.S:82
#1 0x00007f5eecb74aeb in google::LogMessage::SendToLog() () from /lib64/libglog.so.0
#2 0x00007f5eecb71fc7 in google::LogMessage::Flush() () from /lib64/libglog.so.0
#3 0x00007f5eecb721a9 in google::LogMessage::~LogMessage() () from /lib64/libglog.so.0
#4 0x00000000004874a6 in LSDB::process (this=0x242d918, lsp=0x25f9200, circuit=0x24c7af0) at ../src/model/trill/LSDB.cpp:481
#5 0x00000000004a0f6f in Circuit::rx (this=0x24c7af0, eth=0x246fdf0) at ../src/model/trill/Circuit.cpp:355
#6 0x000000000045c950 in Circuit::qt_static_metacall (_o=0x24c7af0, _c=QMetaObject::InvokeMetaMethod, _id=0, _a=0x7fffaade95a0)
at ../src/model/trill/Circuit.moc.cpp:55
#7 0x000000398798cb9f in QMetaObject::activate (sender=0x2470140, m=<optimized out>, local_signal_index=<optimized out>, argv=0x7fffaade95a0)
at kernel/qobject.cpp:3547
#8 0x0000000000459610 in FramePublisher::subscription (this=0x2470140, _t1=0x246fdf0) at ../src/model/system/FramePublisher.moc.cpp:98 …Run Code Online (Sandbox Code Playgroud) 使用 CMake 和 emscripten 构建 C++/web-assembly 项目时,install目标命令仅安装.js文件而不安装.wasm文件。
install(TARGETS MyTarget RUNTIME DESTINATION ${CMAKE_BINARY_DIR}/dist)
Run Code Online (Sandbox Code Playgroud)
这将仅安装 JS 文件。我尝试为LIBRARY, RESOURCE, ARCHIVE...添加规则,但从未复制 Wasm。我在官方文档中找不到任何内容。
我知道使用install(FILES ...命令强制复制 wasm很容易解决,但是有没有办法让标准安装对这两个文件都有效?他们都需要作为目标......
我正在尝试构建qtestlib/tutorial1示例,但是当我运行时没有生成testqstring.moc文件nmake(我在Windows XP SP3上运行Qt 4.5.2).
我将testqstring.cpp从tutorial目录复制到我的构建目录(C:\ sandboxes\testqstring),并从Qt命令提示符运行我的MS Visual Studio 8安装中的vsvars32.bat文件来添加VS环境变量.
根据教程,我应该运行:
> qmake -project "CONFIG += qtestlib"
> qmake
> nmake
Run Code Online (Sandbox Code Playgroud)
当我这样做时,输出nmake是:
C:/Apps/Qt/2009.03/qt/bin\moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_TESTLIB_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"....\Apps\Qt\2009.03\qt\include\QtCore" -I"....\Apps\Qt\2009.03\qt\include\QtGui"-I"....\Apps\Qt\2009.03\qt\include\QtTest"-I"....\Apps\Qt\2009.03\qt\include"-I"." -I"....\Apps\Qt\2009.03\qt\include\ActiveQt"-I"debug"-I"....\Apps\Qt\2009.03\qt\mkspecs\win32-g ++"-D__GNUC__ - DWIN32 testqstring.cpp -o debug\testqstring.moc
g ++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_TESTLIB_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -I"....\Apps\Qt\2009.03\qt\include\QtCore"-I" ....\Apps\Qt\2009.03\qt\include\QtGui"-I"....\Apps\Qt\2009.03\qt\include\QtTest"-I"....\Apps\Qt\2009.03\qt\include"-I"." -I"....\Apps\Qt\2009.03\qt\include\ActiveQt"-I"debug"-I"....\Apps\Qt\2009.03\qt\mkspecs\win32-g ++"-o debug\testqstring.o testqstring.cpp
testqstring.cpp:63:27:testqstring.moc:没有这样的文件或目录
NMAKE:致命错误U1077:'C:\ Apps\Qt\2009.03\mingw\bin\g ++.EXE':返回代码'0x1'停止.
NMAKE:致命错误U1077:'C:\ PROGRA~1\MICROS~3\VC\BIN \nmake.exe':返回代码'0x2'停止.
所以,我可以看到正在调用moc.exe来生成debug/testqstring.moc,但是从不生成该文件.
感谢您提供的任何和所有指导.
我在QML中得到一个数组未定义的错误,我想知道什么会修复这个错误.这是当前的代码:
opacity: mBitField[index]
Run Code Online (Sandbox Code Playgroud)
每隔一段时间它会说不能分配undefined给opacity我,我想知道这个修复是否有效:
opacity: mBitField[index] == "undefined" ? 0 : mBitField[index]
Run Code Online (Sandbox Code Playgroud)
基本上我想说的是如果数组是未定义的,可以分配一个0,opacity否则在数组中分配什么.
无关信息: 我正在尝试使用Qt构建应用程序.此应用程序具有QMdiArea和子窗口.我的儿童窗口将有一个菜单,可以集成到QMdiArea或隔离并附加到孩子本身.虽然,这比需要的更详细一点......
问题: 我希望我的子窗口小部件有一个带有快捷方式的菜单,"CTRL + W".但是,因为我使用的是QMdiArea,所以已使用快捷方式导致:
QAction :: eventFilter:模糊的快捷方式重载:Ctrl + W.
我怎样才能摆脱这个快捷方式并在我的子窗口小部件中声明它?
更新: 这是我没有运气的尝试:
class MDI : public QMdiArea
{
Q_OBJECT
private:
bool event(QEvent *tEvent)
{
if (tEvent->type() == QEvent::KeyPress)
{
QKeyEvent* ke = static_cast<QKeyEvent*>(tEvent);
if (ke->key()== Qt::Key_W && ke->modifiers() & Qt::ControlModifier)
emit KeyCW();
return true;
}
return QMdiArea::event(tEvent);
}
public:
signals:
void KeyCW();
};
Run Code Online (Sandbox Code Playgroud)
这工作,如果我做的改变简单的东西Qt::Key_W来 Qt::Key_L.的关键,组合体被接收的事件被抛出.有了W,它就永远不会发生.我也尝试过移动event到QMainWindow以及子窗口中的eventFilter到QMdiArea.似乎做一些简单的事情就像从QMdiArea中删除默认的键处理程序一样简单.
我正在尝试使用样式表在 QFrame 内设置 2 个标签的悬停状态颜色,但无论是否存在实际悬停,框架都会采用悬停状态:
我有一个带有 QLabels 的 QFrame。我将默认颜色设置为绿色和紫色。当我将鼠标悬停在 QFrame 上时,两个标签的颜色都应该变成红色。
在完全相同的CSS没有工作的HTML,但我似乎无法将其与QT样式表开始工作。
div{background-color:black; width:200px; height:100px;}
#label1{color: green;}
#label2{color: purple;}
div:hover #label1 {color: red;}
div:hover #label2 {color:red;}
Run Code Online (Sandbox Code Playgroud) 在一个大型 QML 项目中,有时我会收到以下错误:
MyItem.qml:8: TypeError: 无法读取 null 的属性
当我查看相关行时,它总是在一个子项中,具有一个属性绑定到一个父属性,如
Item
{
id: myItem
ASubItem
{
id: subItem
width: parent.width
}
}
Run Code Online (Sandbox Code Playgroud)
因此,父项似乎变为空,并且内部项在此之后尝试更新其属性。
我们有时会从 C++ 中删除项目,因为我们想创建新项目,这似乎是错误消息的原因。我们还从 C++ 创建了一些项目(使用QQmlComponent)并将父项和父项设置为QQuickItem包含这些项目的 ,但似乎我在其他项目上也遇到了这个错误。
但我不明白为什么内部项目会在父项为空时尝试更新自己,不应该同时删除它吗?
有什么方法可以调试它以查看父项何时被删除以及其子项何时尝试更新?
qt ×9
c++ ×4
qml ×2
cmake ×1
emscripten ×1
glog ×1
io ×1
nmake ×1
qmake ×1
qmdiarea ×1
qprocess ×1
qt-creator ×1
qthread ×1
stylesheet ×1
unix ×1