请考虑以下逻辑流程:
1. App started
2. functionA() triggered
3. the app periodically capture some images to external files
4. end of functionA()
5. the app create a video from captured images, using ffmpeg as external program
6. [step 2 -> step 5] may be repeated.
7. App quit
Run Code Online (Sandbox Code Playgroud)
为了实现这个流程,我使用QProcess启动外部程序让我加入图像,但是我对QProcess的正确使用模式感到困惑.(我不关心ffmpeg的控制台消息,我通过检查是否创建了视频文件来确定步骤5的成功.)
尝试1
void MyWidget::createAVI()
{
checkAndDeleteAVI();
process = new QProcess(this); // process_ defined as class member;
process->start("ffmpeg -f images2 ....");
process->waitForFinished(-1); // (a)
// (b)
}
Run Code Online (Sandbox Code Playgroud)
在(a),我读了这个调用可以冻结主GUI的文档,所以我应该从QThread/QRunnable调用吗?
在(b),我错过了什么吗?当我试图关闭应用程序时(流程中的第7步),应用程序崩溃了,我认为生成的QProcess没有正确发布.
尝试2
我编写了一个QProcess的包装类,如下所示: …
我正在使用包含文件名行(相对于当前目录)的配置文件移植到控制台程序到Qt.当我在QtCreator中运行/调试GUI时,似乎无法从工作目录加载文件.
假设我的文件系统如下:
C:/MyProjectSource
C:/MyProjectSource-Desktop-Debug // <-- created by QtCreator
C:/MyProjectSource-Desktop-Debug/debug/MyProgram.exe // <- my program
C:/MyProjectSource-Desktop-Debug/debug/params.txt // <- program's config
C:/MyProjectSource-Desktop-Debug/debug/cfg/file1.txt // <- extra file
C:/MyProjectSource-Desktop-Debug/debug/cfg/file2.txt // <- extra file
Run Code Online (Sandbox Code Playgroud)
params.txt看起来像
# other setting
...
cfg/file1.txt # at this line, program crash, saying cannot open file
cfg/file2.txt
...
# other setting
Run Code Online (Sandbox Code Playgroud)
用于读取file1.txt的代码
std::ifstream ifs(filename); // <-- @runtime, filename = 'cfg/file1.txt'
if (!ifs)
{
// failed inside QtCreator, but fine when start from explorer
EMSG_OPENFILE(filename);
exit(-1);
}
Run Code Online (Sandbox Code Playgroud)
基线:如果可能,不要更改控制台程序.那么,如何告诉QtCreator了解相对路径?或者我应该在params.txt中强制执行绝对路径?谢谢.
平台:QtCreator 2.6.1,Qt4.8,MinGW64,Win 7
如何使 QAbstractTableModel 的数据可检查
我想让用户可以选中或取消选中以下代码中的每个单元格,如何修改代码?
根据 Qt 文档?Qt::CheckStateRole 并设置 Qt::ItemIsUserCheckable 可能会被使用,所以任何人都可以给出一个小样本?
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MyModel(QAbstractTableModel):
def __init__(self, parent=None):
super(MyModel, self).__init__(parent)
def rowCount(self, parent = QModelIndex()):
return 2
def columnCount(self,parent = QModelIndex()) :
return 3
def data(self,index, role = Qt.DisplayRole) :
if (role == Qt.DisplayRole):
return "Row{}, Column{}".format(index.row() + 1, index.column() +1)
return None
if __name__ == '__main__':
app =QApplication(sys.argv)
tableView=QTableView()
myModel = MyModel (None);
tableView.setModel( myModel );
tableView.show();
sys.exit(app.exec_())
Run Code Online (Sandbox Code Playgroud) 我的程序似乎总是产生荒谬的错误.请为我提供指示.以下代码段剪切掉所有不相关的部分.谢谢.
代码段的A部分似乎无法正确初始化数组,如何调试?代码段的B部分总是崩溃,有什么我想念的吗?
typedef unsigned long T_PSIZE;
int main()
{
int AG_TOTAL = 6 ;
/* part A1 */
T_PSIZE* cntPeopleByAge = new T_PSIZE[AG_TOTAL + 1];
/* part A2 - originally i use static array like this, but it also fails */
//T_PSIZE cntPeopleByAge T_PSIZE[AG_TOTAL + 1];
for (int i = 0; i < (AG_TOTAL + 1); i++)
{
std::cout << i << ":" << cntPeopleByAge[i] << "\t";
cntPeopleByAge[i] = 0;
std::cout << cntPeopleByAge[i] << "\n";
}
std::cout << "cntPeopleByAge:" << …
Run Code Online (Sandbox Code Playgroud) 平台:MinGW64(rubenvb 4.7.2),Windows 7(64),Qt 4.8.2
给定代码段如下:
/* type definition */
typedef long T_PSIZE;
struct A { T_PSIZE myArray[10]; };
struct B { T_PSIZE myArray[10]; };
/* declare variable */
A a;
B b;
std::copy(a.myArray[0], a.myArray[10], &b.myArray);
Run Code Online (Sandbox Code Playgroud)
我不知道为什么编译器抛出以下错误消息(当从'typedef long T_PSIZE''更改为'typedef int T_PSIZE'时,也会显示类似的消息):
> c:\mingw\rubenvb-4.7.2-64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/bits/stl_algobase.h:
> In instantiation of '_OI std::__copy_move_a(_II, _II, _OI) [with bool
> _IsMove = false; _II = long int; _OI = long int (*)[9]]': c:\mingw\rubenvb-4.7.2-64\bin\../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/bits/stl_algobase.h:422:39:
> required from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool
> _IsMove = false; _II …
Run Code Online (Sandbox Code Playgroud)