原理
c = 质数数组长度,除不了就c--,都除不了c==0,while(0)退出循环。
mainwindow.h
struct WbiH {
int width;
int height;
};
WbiH calcWbiH(int w, int h);
mainwindow.cpp
{
......
int width = player->metaData(SLMD.at(i)).toSize().width();
int height = player->metaData(SLMD.at(i)).toSize().height();
WbiH wbih = calcWbiH(width, height);
//qDebug() << wbih.width << "X" << wbih.height;
s += SLMD.at(i) + ": " + QString::number(width) + " X " + QString::number(height) + " (" + QString::number(wbih.width) + ":" + QString::number(wbih.height) + ")\n";
......
}
WbiH MainWindow::calcWbiH(int w, int h)
{
QList<int> zs;
zs << 2 << 3 << 5 << 7 << 11;
int c = zs.length();
while (c) {
c = zs.length();
for (int i=0; i<zs.length(); i++) {
if (w % zs.at(i) == 0 && h % zs.at(i) == 0) {
w = w / zs.at(i);
h = h / zs.at(i);
} else {
c--;
}
}
qDebug() << c;
}
return WbiH{w, h};
}