Qt使用小技巧
1,switch 使用:如果在case语句中定义变量 需要把 case 后面的代码用大括号括起来 否则会提示《 error: C2361: “default”标签跳过“time”的初始化操作》错误。
如
case libvlc_MediaPlayerTimeChanged:
qDebug()<<"New time is"<<event->u.media_player_time_changed.new_time;
int time = event->u.media_player_time_changed.new_time;
emit obj->playCurrentTime(time/1000);
break;
需要改为
case libvlc_MediaPlayerTimeChanged:{
qDebug()<<"New time is"<<event->u.media_player_time_changed.new_time;
int time = event->u.media_player_time_changed.new_time;
emit obj->playCurrentTime(time/1000);
break;}