当前位置: 代码迷 >> QT开发 >> 新手求教window下qt 图片显示
  详细解决方案

新手求教window下qt 图片显示

热度:12   发布时间:2016-04-25 04:23:24.0
新手求教window上qt 图片显示
在window上qt的图片显示路径是不是必须要用决定路径?就是比如我把图片放在E盘下的test文件加下的images文件夹,图片的路径就必须写成E:/test/images/图片名?test是工程文件。
不过这样有一个问题,就是把这个程序放到其他的电脑上路径不对,图片就显示不出来了。求高手怎么办才好呢!非常感谢了
------最佳解决方案--------------------
不用担心,当然可以用相对路径,你可以将图片放在你的项目目录下,用QApplication::applicationDirPath()+ /test/images来获取软件所运行的电脑上的图片所在的绝对路径。
------其他解决方案--------------------
如果在QtCreator里运行程序,QApp的目录就是编译出来的exe所在的目录,图片要在那个目录里。
一般QtCreator编译产生的目录如下:
D:\xxxx\qt\fr\fr-build-desktop-Qt_4_8_3__4_8_3____\debug\???.exe

splash->setPixmap(QPixmap(QApplication::applicationDirPath()+ "/test23/splash.jpg")); 
按照上面一行的写法,图片应该放在:
D:\xxxx\qt\fr\fr-build-desktop-Qt_4_8_3__4_8_3____\debug\test23\splash.jpg
------其他解决方案--------------------
引用:
不用担心,当然可以用相对路径,你可以将图片放在你的项目目录下,用QApplication::applicationDirPath()+ /test/images来获取软件所运行的电脑上的图片所在的绝对路径。

我的是这样写的为什么不行呢?splash->setPixmap(QPixmap("QApplication::applicationDirPath()+ /test23/splash.jpg")); 
------其他解决方案--------------------
引用:
引用:不用担心,当然可以用相对路径,你可以将图片放在你的项目目录下,用QApplication::applicationDirPath()+ /test/images来获取软件所运行的电脑上的图片所在的绝对路径。
我的是这样写的为什么不行呢?splash->setPixmap(QPixmap("QApplication::applicatio……


啊?居然把:QApplicat ... 这段也放在了 双引号内 。。。
------其他解决方案--------------------
你写成这样应该splash->setPixmap(QPixmap(QApplication::applicationDirPath()+ "/test23/splash.jpg")); 
------其他解决方案--------------------
谢了!!!!!
------其他解决方案--------------------
引用:
你写成这样应该splash->setPixmap(QPixmap(QApplication::applicationDirPath()+ "/test23/splash.jpg"));


我改了,为什么还是不可以呢?要加什么头文件吗?谢了!
------其他解决方案--------------------
把这个路径 print 出来,看看是否有错。
------其他解决方案--------------------
大侠们,这是我写的代码!看看怎么弄呢?
#include <QApplication>
#include <QSplashScreen>
#include <QPixmap>
//#include "mainwindow.h"
#include "shapewidget.h"
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
QSplashScreen *splash = new QSplashScreen;
//splash->setPixmap(QPixmap("E:/qt/daima/test23/splash.jpg")); //这样可以
        splash->setPixmap(QPixmap(QApplication::applicationDirPath()+ "test23/splash.jpg"));  //这样不可以,显示不出来图片 
    splash->show();

   
    int a=60000,i=0;
    for(i=2;i>0;i--)
while( a--);
    delete splash;
    ShapeWidget shape;
    shape.show();
   
    return app.exec();
}

------其他解决方案--------------------
 splash->setPixmap(QPixmap(QApplication::applicationDirPath()+ "/test23/splash.jpg")); 
test23前面需要有一个/
------其他解决方案--------------------
  相关解决方案