错误:从'void'转换为请求的非标量类型'QString'

问题描述 投票:-1回答:1
#include "mainwindow.h"
#include <QApplication>
#include <QString>
#include <QDebug>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    QString h;
    h = "fsdfsdfsf";

    QString j = h.chop(3);
    qDebug() << "j: " << j;

    return a.exec();
}

输出:

error: conversion from ‘void’ to non-scalar type ‘QString’ requested

我在哪里错了?

c++ qt5
1个回答
2
投票

错误的原因是QString::chop()从调用它的字符串中删除字符,并且不返回任何内容(返回void)。

您有两种选择:

© www.soinside.com 2019 - 2024. All rights reserved.