现在的位置: 首页 > 综合 > 正文

Qt例程

2014年03月24日 ⁄ 综合 ⁄ 共 372字 ⁄ 字号 评论关闭

读文件
QFile dictionaryFile(":/dictionary/words.txt");

     dictionaryFile.open(QIODevice::ReadOnly);
     QTextStream inputStream(&dictionaryFile);

     int x = 5;
     int y = 5;

     while (!inputStream.atEnd()) {
         QString word;
         inputStream >> word;
         if (!word.isEmpty()) {
             DragLabel *wordLabel = new DragLabel(word, this);
             wordLabel->move(x, y);
             wordLabel->show();
             x += wordLabel->width() + 2;
             if (x >= 195) {
                 x = 5;
                 y += wordLabel->height() + 2;
             }
         }
     }

抱歉!评论已关闭.