Chinaunix首页 | 论坛 | 博客
  • 博客访问: 215984
  • 博文数量: 145
  • 博客积分: 3000
  • 博客等级: 中校
  • 技术积分: 1720
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-14 18:42
文章分类

全部博文(145)

文章存档

2011年(1)

2009年(144)

我的朋友

分类: LINUX

2009-07-22 18:59:32

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) |
给主人留下些什么吧!~~