Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 是否有设置的“准备使用”对话框?_C++_Qt - Fatal编程技术网

C++ 是否有设置的“准备使用”对话框?

C++ 是否有设置的“准备使用”对话框?,c++,qt,C++,Qt,这里有一个想法:我有一个参数列表(名称、类型、值,可能还有其他一些-regex用于输入),按部分分组。它们存储在xml文件中(例如,可能是其他格式)。我想让一个模块,建立“标准外观”设置对话框依赖于这个文件。这样地 节名称应作为列表显示在左侧,参考选定节的参数应位于右侧:名称作为标签,值作为某些输入字段,其类型取决于参数的类型(文本的lineEdit,数字的SpineEdit,布尔值的checkBox,等等) 最后一个问题:是否有“准备使用”对话框供我使用? 谢谢。没有这样的对话框 手动创建“完

这里有一个想法:我有一个参数列表(名称、类型、值,可能还有其他一些-regex用于输入),按部分分组。它们存储在xml文件中(例如,可能是其他格式)。我想让一个模块,建立“标准外观”设置对话框依赖于这个文件。这样地 节名称应作为列表显示在左侧,参考选定节的参数应位于右侧:名称作为标签,值作为某些输入字段,其类型取决于参数的类型(文本的lineEdit,数字的SpineEdit,布尔值的checkBox,等等) 最后一个问题:是否有“准备使用”对话框供我使用?
谢谢。

没有这样的对话框


手动创建“完整”对话框,然后禁用/隐藏在特定情况下未使用的元素如何?

我搜索了一些时间,没有找到任何决定。这就是我决定自己写的原因。 这里有一点描述:

1主要概念

如果您的程序有一些参数,您希望可以从GUI进行编辑,那么您只需以适当的格式编写xml文件,创建一个类Config的实例,调用slot Config::show(),最后通过Config::get()请求必要的参数

2类配置的使用

你可以随心所欲地创建它。您可以在c-tor或Config::load()方法中提供xml文件名/路径。您可以通过以下方式在程序的任何位置获取任何参数: 正在调用Config::get()方法。类配置的用法示例:

Config config( "full/path/to/settings.xml" );
connect( settingsAction, SIGNAL( trigger() ), &config, SLOT( show() ) );
... 
if ( config.get( "section_name", "param_name" ).toBool() ) {
    ...
}
QFile file( config.get( "section_name", "directory_for_log" ).toString() +
    "/prog.log" );
3限制

配置需要QtCore、QtGui和QtXml。它使用C++11的特性

4 Xml文件格式

对不起,我懒得写完整的描述,所以我将写一个包含所有特性的完整示例。我想,你会理解所有这些:)


这是一张照片

下面是Config在这个文件中的用法

std::ostream & operator<< ( std::ostream & os, const QVariant & var ) {
    if ( var.type() == QVariant::Bool ) {
        os << var.toBool();
    }
    else if ( var.type() == QVariant::Int ) {
        os << var.toInt();
    }
    else if ( var.type() == QVariant::String ) {
        os << qPrintable( var.toString() );
    }
    return os; }

cout << "First group checked : " << cfg.get( "First section name", "First group" ) << endl;
cout << "Ip address:port : " << cfg.get( "First section name", "Ip address:port" ) << endl;
cout << "Some bool value : " << cfg.get( "First section name", "Some bool value" ) << endl;
cout << "Choose 1 : " << cfg.get( "First section name", "Choose 1" ) << endl;
cout << "Picture or sound : " << cfg.get( "First section name", "Picture or sound" ) << endl;
cout << "Choose 2 : " << cfg.get( "First section name", "Choose 2" ) << endl;
cout << "Dir for log : " << cfg.get( "First section name", "Dir for log" ) << endl;
cout << "Length : " << cfg.get( "First section name", "Length" ) << endl;
cout << "Weight : " << cfg.get( "First section name", "Weight" ) << endl;
cout << "Just bool : " << cfg.get( "First section name", "Just bool" ) << endl;
cout << "Greet me : " << cfg.get( "Second sect", "Greet me" ) << endl;
cout << "Invisible bool : " << cfg.get( "Second sect", "Invisible bool" ) << endl;

std::ostream&operator简短的回答是否定的。长的回答是可能有人做了,所以做一些谷歌搜索。如果你仍然找不到任何东西,为什么不自己制作并发布给其他人使用呢?好的,谢谢。我在谷歌上搜索了很多,但没有成功。如果找不到现成的解决方案,我当然会发布它。顺便说一句,我在PSI IM中看到了类似的东西…我不明白什么是“完整”对话框。。。我想为我的所有(或大多数)GUI项目制作带有此类对话框的多用途模块,这些项目需要定制。当您需要创建解析器来读取xml/json/任何配置,然后向GUI添加特定对话框时。neciu,我很清楚这一点,但我不想发明自行车。如果我找不到ready模块,当然我会自己写
std::ostream & operator<< ( std::ostream & os, const QVariant & var ) {
    if ( var.type() == QVariant::Bool ) {
        os << var.toBool();
    }
    else if ( var.type() == QVariant::Int ) {
        os << var.toInt();
    }
    else if ( var.type() == QVariant::String ) {
        os << qPrintable( var.toString() );
    }
    return os; }

cout << "First group checked : " << cfg.get( "First section name", "First group" ) << endl;
cout << "Ip address:port : " << cfg.get( "First section name", "Ip address:port" ) << endl;
cout << "Some bool value : " << cfg.get( "First section name", "Some bool value" ) << endl;
cout << "Choose 1 : " << cfg.get( "First section name", "Choose 1" ) << endl;
cout << "Picture or sound : " << cfg.get( "First section name", "Picture or sound" ) << endl;
cout << "Choose 2 : " << cfg.get( "First section name", "Choose 2" ) << endl;
cout << "Dir for log : " << cfg.get( "First section name", "Dir for log" ) << endl;
cout << "Length : " << cfg.get( "First section name", "Length" ) << endl;
cout << "Weight : " << cfg.get( "First section name", "Weight" ) << endl;
cout << "Just bool : " << cfg.get( "First section name", "Just bool" ) << endl;
cout << "Greet me : " << cfg.get( "Second sect", "Greet me" ) << endl;
cout << "Invisible bool : " << cfg.get( "Second sect", "Invisible bool" ) << endl;