在向qLabel显示图像时,QT无法检测输入文件

时间:2016-10-05 20:52:26

标签: c++ qt qpixmap qlabel

尝试使用“{/ logo-here”我的.qrc文件显示图片资源时,我一直收到错误

No input files specified.

这是编译器错误段

/opt/qt/Qt5.7.0/5.7/gcc_64/bin/rcc -name  ../VPN/.qrc -o qrc_.cpp
/opt/qt/Qt5.7.0/5.7/gcc_64/bin/rcc: No input files specified.
Usage: /opt/qt/Qt5.7.0/5.7/gcc_64/bin/rcc [options] inputs

我的.qrc文件

<RCC>
    <qresource prefix="/">
        <file alias="logo">back.png</file>
    </qresource>
</RCC>

我可以从qt资源管理器打开图像,因此qt确实有正确的路径,但不知怎的,我错过了一些东西......

有什么建议吗?

额外信息:

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtCore>
#include <QtGui>
#include <QtWidgets>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    //QGraphicsView *view;
    //QGraphicsScene *scene;
};

#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QPixmap pixmapTarget = QPixmap(":/back.png");
    //QPixmap pixmapTarget = QPixmap(":/logo");
    ui->label->setPixmap(pixmapTarget );
}

MainWindow::~MainWindow()
{
    delete ui;
}

完整编译器输出

22:42:44: Running steps for project VPN...
22:42:44: Configuration unchanged, skipping qmake step.
22:42:44: Starting: "/usr/bin/make" 
g++ -c -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../VPN -I. -I/opt/qt/Qt5.7.0/5.7/gcc_64/include -I/opt/qt/Qt5.7.0/5.7/gcc_64/include/QtWidgets -I/opt/qt/Qt5.7.0/5.7/gcc_64/include/QtGui -I/opt/qt/Qt5.7.0/5.7/gcc_64/include/QtCore -I. -I. -I/opt/qt/Qt5.7.0/5.7/gcc_64/mkspecs/linux-g++ -o mainwindow.o ../VPN/mainwindow.cpp
/opt/qt/Qt5.7.0/5.7/gcc_64/bin/rcc -name  ../VPN/.qrc -o qrc_.cpp
/opt/qt/Qt5.7.0/5.7/gcc_64/bin/rcc: No input files specified.
Usage: /opt/qt/Qt5.7.0/5.7/gcc_64/bin/rcc [options] inputs
Qt Resource Compiler version 5.7.0

Options:
  -h, --help           Displays this help.
  -v, --version        Displays version information.
  -o, --output <file>  Write output to <file> rather than stdout.
  -t, --temp <file>    Use temporary <file> for big resources.
  --name <name>        Create an external initialization function with <name>.
  --root <path>        Prefix resource access path with root path.
  --compress <level>   Compress input files by <level>.
  --no-compress        Disable all compression.
  --threshold <level>  Threshold to consider compressing files.
  --binary             Output a binary file for use as a dynamic resource.
  --pass <number>      Pass number for big resources
  --namespace          Turn off namespace macros.
  --verbose            Enable verbose mode.
  --list               Only list .qrc file entries, do not generate code.
  --project            Output a resource file containing all files from the
                       current directory.

Arguments:
  inputs               Input files (*.qrc).
Makefile:589: recipe for target 'qrc_.cpp' failed
make: *** [qrc_.cpp] Error 1
22:42:48: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project VPN (kit: Desktop Qt 5.7.0 GCC 64bit)
When executing step "Make"
22:42:48: Elapsed time: 00:03.

1 个答案:

答案 0 :(得分:0)

可能是因为您使用的是<qresource prefix="/">,因此您需要在资源路径中添加额外的/QPixmap("://back.png");

注意:您可以使用Qt Creator并从左侧的文件层次结构转到您的资源,然后右键单击您想要的资源,然后选择复制资源路径,这是您可以使用的路径。