Qt连接mysql查询数据

QSqlDatabase db=QSqlDatabase::addDatabase("QMYSQL");
       db.setHostName("127.0.0.1");//mysql的地址
       db.setPort(3306);
       db.setDatabaseName("thinkcmf");//连接的数据库名称
       db.setUserName("root");//mysql登录名
       db.setPassword("xxx");//mysql密码
       if(db.open())
       {
           qDebug()<<"success!";
            qDebug()<"show tables from thinkcmf");//thinkcmf数据库里的所有表
            while (query.next()) {
                QString country = query.value(0).toString();
                qDebug()<"select * from thinkcmf_menu");//查询表的内容
            while (query1.next()) {
                QString country = query1.value(0).toString();//cmf_menu表第1个字段的内容
                qDebug()<else{
           qDebug()<<"failure";
       }

你可能感兴趣的:(C++,Qt)