标签: qstring

QString .arg 函数

我目前正在 QT 中使用 QStrings,似乎无法理解为什么以下代码对我不起作用。

#include <QCoreApplication>
#include <QDebug>
#include <QString>
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    QString test;

    int x = 5;

    test.append("This is a test of the Arg Function %1").arg(x);
    qDebug() << test;
    //should output This is a test of the Arg Function 5
    return a.exec();
}
Run Code Online (Sandbox Code Playgroud)

我得到的输出是:

这是对 Arg 函数 %1 的测试

显然我期望值 5 替换 %1,我在这里遗漏了一些明显的东西吗?

c++ qstring qt

0
推荐指数
1
解决办法
3111
查看次数

如何在 QString 中插入 unicode 特殊字符?

我正在尝试将一个特殊的 unicode 字符 (0xFD3F) 插入到 QString 中。

我尝试创建,QChar(0xFD3F)但是当输出这个字符并在十六进制编辑器中查看它时,它显示0x3F3F. 我也找不到QString通过十六进制或十进制表示插入字符的函数。

unicode qstring qt

0
推荐指数
1
解决办法
4903
查看次数

无法将 QString 转换为 Const Char*

我是 QT 的新手,所以如果我在这里公然做错了什么,请原谅我,但我已经查看了这里有关此事的所有问题,但似乎找不到有效的方法。我试图让用户通过输入名称来创建一个文件夹,然后它会使用该名称“创建”一个文件夹。我说“创建”是因为它并不完全是创建一个,它在您输入名称之前首先创建一个名为“project”的文件夹,当您输入名称时它会重命名它。但是,当我尝试使用输入的名称重命名文件夹时,它给了我

错误:C2664:“int rename(const char *,const char *)”:无法将参数1从“QString”转换为“const char *”

这是我的代码:

    void MainWindow::on_actionNew_Project_triggered(const char *parameter)
{
    //Create project folder
    QString projectPath = "D:/Project";

    QDir dir(projectPath);
        if (!dir.exists()) {
            dir.mkpath(projectPath);
    }


    //Get project name from user
    bool result;
    QString name = QInputDialog::getText(0, "New Project",
                                             "Enter in project name", QLineEdit::Normal,
                                             "", &result);
    if(result && !name.isEmpty()) {

    //Rename project folder to user created name
    QDir dir(projectPath);
        if (dir.exists()) {
            rename(projectPath, name); //Gives me error HERE

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果你们能帮忙,我将不胜感激,我已经在这个问题上坚持了几个小时了。

c++ qstring qt compiler-errors const-char

0
推荐指数
1
解决办法
9043
查看次数

更改 QStringList 的第 i 个元素

我正在寻找解决方案半个小时,但没有进展。

考虑清单

QStringList foo = {};
for (int i=1; i<8; i++){
    foo << "0";
}
Run Code Online (Sandbox Code Playgroud)

如果单击某个复选框,我想将列表的值更改为"1"

那么,例如,如何将第三个更改01?类似(伪代码)的东西foo.replace(3,"0","1")

qstring replace qt5

0
推荐指数
1
解决办法
4839
查看次数

为什么我不能在这里使用QString :: arg函数?

您知道在任何需要QString对象作为参数的地方,您只能使用c样式字符串.例如,showMessage函数需要QString.但是我将一个C风格的字符串传递给了这个函数,每件事都没问题.我的意思是在这里我们可以把它想象 "%1 a sample text"成一个QString对象!也许!

statusBar()->showMessage("%1 a sample text");
Run Code Online (Sandbox Code Playgroud)

但为什么我们不能使用这段代码:

statusBar()->showMessage("%1 a sample text".arg("This is "));
Run Code Online (Sandbox Code Playgroud)

c++ qstring qt

-1
推荐指数
1
解决办法
113
查看次数

标签 统计

qstring ×5

qt ×4

c++ ×3

compiler-errors ×1

const-char ×1

qt5 ×1

replace ×1

unicode ×1