QtCreator欢迎界面示例为空问题

QtCreator内部加载examples是这样子的:

1.先找Qt Doc目录(可以使用qmake -query QT_INSTALL_DOCS命令查看相关路径),然后从它的每个子目录下查找'examples-manifest.xml'和'demos-manifest.xml'文件。

2.找到了之后,以qt gui 的'Analog Clock Window Example'为例,比如Qt Doc是在/usr/share/qt5/doc下,那么该示例就在/usr/share/qt5/doc/qtgui/examples-manifest.xml文件中记录着,如:

<example name="Analog Clock Window Example" docUrl="qthelp://org.qt-project.qtgui.5113/qtgui/qtgui-analogclock-example.html" projectPath="gui/analogclock/analogclock.pro" imageUrl="qthelp://org.qt-project.qtgui.5113/qtgui/images/analogclock-window-example.png" isHighlighted="true">
            <description><![CDATA[The Analog Clock Window example shows how to draw the contents of a custom window.]]></description>            <tags>analog,android,clock,gui,ios,window</tags>
            <fileToOpen mainFile="true">gui/analogclock/main.cpp</fileToOpen>
        </example>

3.然后还要去验证该示例的对应值' projectPath'、'imageUrl'和'docUrl'是否有效,注意projectPath是指相对于example/demo本身的路径,可以使用qmake -query QT_INSTALL_EXAMPLESqmake -query QT_INSTALL_DEMOS查看具体示例所在路径,我这边这两个是一样的,好像没什么区别。而imageUrldocUrl则是相对于doc路径,比如该示例绝对路径分别为/usr/share/qt5/doc/qtgui/images/analogclock-window-example.png/usr/share/qt5/doc/qtgui/qtgui-analogclock-example.html

4.这样的话如果QtCreator不显示示例,可以去看看Qt Doc目录是否为空,还有使用qmake -query QT_INSTALL_EXAMPLES看下示例具体的目录是否为空,如果为空那显示不出来就正常。

5.QtCreator源码src/plugins/qtsupport/exampleslistmodel.cpp中有使用到环境变量'QTC_DEBUG_EXAMPLESMODEL'来调试examples加载过程:

static bool debugExamples()
{   
    static bool isDebugging = qEnvironmentVariableIsSet("QTC_DEBUG_EXAMPLESMODEL");
    return isDebugging;
}
......
// read extra example sets settings
QSettings *settings = Core::ICore::settings();
const QStringList list = settings->value("Help/InstalledExamples", QStringList()).toStringList();
if (debugExamples())
     qWarning() << "Reading Help/InstalledExamples from settings:" << list; 

会去QtCreator.ini配置文件中查看'Help/InstalledExamples'对应example值,当然一般是没有的,因为我就没有看到。不过可以考虑把自定义的example放到这里去在QtCreator中显示。这个变量主要是调试输出使用的,比如qtcreator启动时输出:

Reading Help/InstalledExamples from settings: ()
"Reading file \":/qtsupport/qtcreator_tutorials.xml\"..."
"ERROR: Could not parse file as XML document (:/qtsupport/qtcreator_tutorials.xml)"
"Reading file \"/usr/share/qt5/doc/qdoc/examples-manifest.xml\"..."
"ERROR: Item \"QML Documentation Example\" broken: projectPath \"/usr/share/qt5/doc/qdoc/componentset/componentset.pro\" empty or does not exist"
"Reading file \"/usr/share/qt5/doc/qt3d/examples-manifest.xml\"..."
"Reading file \"/usr/share/qt5/doc/qtassistant/examples-manifest.xml\"..."
"Reading file \"/usr/share/qt5/doc/qtbluetooth/examples-manifest.xml\"..."
"Reading file \"/usr/share/qt5/doc/qtcharts/examples-manifest.xml\"..."
"ERROR: Item \"Audio Example\" broken: projectPath \"/usr/share/qt5/doc/qtcharts/charts/audio/audio.pro\" empty or does not exist"
"Reading file \"/usr/share/qt5/doc/qtconcurrent/examples-manifest.xml\"..."
"Reading file \"/usr/share/qt5/doc/qtcore/examples-manifest.xml\"..."
"Reading file \"/usr/share/qt5/doc/qtdbus/examples-manifest.xml\"..."
"Reading file \"/usr/share/qt5/doc/qtdesigner/examples-manifest.xml\"..."
"Reading file \"/usr/share/qt5/doc/qtdoc/examples-manifest.xml\"..."
"ERROR: Item \"Coffee Machine Example\" broken: projectPath \"/usr/share/qt5/doc/qtdoc/demos/coffee/coffee.pro\" empty or does not exist"
"Reading file \"/usr/share/qt5/doc/qtgui/examples-manifest.xml\"..."
"ERROR: Item \"Hello Vulkan Cubes Example\" broken: projectPath \"/usr/share/qt5/doc/qtgui/gui/hellovulkancubes/hellovulkancubes.pro\" empty or does not exist"
"ERROR: Item \"Hello Vulkan Texture Vulkan Example\" broken: projectPath \"/usr/share/qt5/doc/qtgui/gui/hellovulkantexture/hellovulkantexture.pro\" empty or does not exist"
"ERROR: Item \"Hello Vulkan Triangle Example\" broken: projectPath \"/usr/share/qt5/doc/qtgui/gui/hellovulkantriangle/hellovulkantriangle.pro\" empty or does not exist"
"ERROR: Item \"Hello Vulkan Widget Example\" broken: projectPath \"/usr/share/qt5/doc/qtgui/gui/hellovulkanwidget/hellovulkanwidget.pro\" empty or does not exist"
"ERROR: Item \"Hello Vulkan Window Example\" broken: projectPath \"/usr/share/qt5/doc/qtgui/gui/hellovulkanwindow/hellovulkanwindow.pro\" empty or does not exist"
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是一个使用Qt Creator实现图片轮播的示例代码: 1. 创建一个新的Qt Widgets应用程序项目。 2. 在主窗口的设计界面中,添加一个QLabel控件,设置其名称为`label`,并设置其初始大小为400x300。 3. 在主窗口的设计界面中,添加一个QTimer控件,设置其名称为`timer`,并将其超时信号与槽函数`updateImage()`连接起来。 4. 在主窗口的头文件中添加以下代码: ```cpp private: QStringList images; int currentIndex; private slots: void updateImage(); ``` 5. 在主窗口的源文件中添加以下代码: ```cpp #include "mainwindow.h" #include "ui_mainwindow.h" #include <QPixmap> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); // 初始化图片列表 images << "image1.jpg" << "image2.jpg" << "image3.jpg" << "image4.jpg"; currentIndex = 0; // 设置初始图片 updateImage(); // 启动定时器 ui->timer->start(2000); // 每隔2秒切换一张图片 } MainWindow::~MainWindow() { delete ui; } void MainWindow::updateImage() { // 读取当前图片路径 QString imagePath = images[currentIndex]; // 加载并显示图片 QPixmap pixmap(imagePath); ui->label->setPixmap(pixmap.scaled(ui->label->size(), Qt::KeepAspectRatio)); // 更新索引 currentIndex = (currentIndex + 1) % images.size(); } ``` 请注意,上述代码假设你有四张图片(`image1.jpg`,`image2.jpg`,`image3.jpg`和`image4.jpg`)放在与可执行文件相同的目录下。你可以根据实际情况修改图片的路径和数量。 运行上述代码后,将会在主窗口中显示一个大小为400x300的标签,每隔2秒切换一张图片。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值