by tangke <> 2009-06-02
以下代码从italc程序中提取出来,对以后Qt程序启动参数的处理有很好的帮助。
bool core_app = FALSE;
for( int i = 1; i < argc; ++i )
{
if( QString( argv[i] ) == "-rx11vs" ||
QString( argv[i] ) == "-createkeypair" ||
QString( argv[i] ) == "-h" ||
QString( argv[i] ) == "--version" ||
QString( argv[i] ) == "-v" )
{
core_app = TRUE;
}
}
QCoreApplication * app = NULL;
if( core_app )
{
app = new QCoreApplication( argc, argv );
}
else
{
QApplication * a = new QApplication( argc, argv );
a->setQuitOnLastWindowClosed( FALSE );
app = a;
}
QStringListIterator arg_it( QCoreApplication::arguments() );
arg_it.next();
while( argc > 1 && arg_it.hasNext() )
{
const QString & a = arg_it.next();
if( a == "-isdport" && arg_it.hasNext() )
{
__isd_port = arg_it.next().toInt();
}
else if( ( a == "-ivsport" || a == "-rfbport" ) &&
arg_it.hasNext() )
{
__ivs_port = arg_it.next().toInt();
}
#ifdef BUILD_LINUX
else if( a == "-rx11vs" )
{
__rx11vs = TRUE;
}
else if( a == ACCESS_DIALOG_ARG && arg_it.hasNext() )
{
return( isdServer::showAccessDialog( arg_it.next() ) );
}
#endif
else if( a == "-role" )
{
if( arg_it.hasNext() )
{
const QString role = arg_it.next();
if( role == "teacher" )
{
__role = ISD::RoleTeacher;
}
else if( role == "admin" )
{
__role = ISD::RoleAdmin;
}
else if( role == "supporter" )
{
__role = ISD::RoleSupporter;
}
}
else
{
printf( "-role needs an argument:\n"
" teacher\n"
" admin\n"
" supporter\n\n" );
return( -1 );
}
}
}
阅读(704) | 评论(0) | 转发(0) |