Работя върху симулатор на C++/Qt, който интегрира страница на параметър. В края на параметрите QLabel
уведомява потребителя дали въведените данни са валидни или не. Този текст трябва да се появи с персонализиран цвят, така че внедрих това:
ParametersDialog.h
#include <iostream>
#include <QtWidgets>
using namespace std;
class ParametersDialog: public QDialog {
Q_OBJECT
public:
ParametersDialog(QWidget *parent = nullptr);
~ParametersDialog();
...
private:
QLabel *notificationLabel = new QLabel;
...
void notify(string message, string color);
};
ParametersDialog.cpp
#include "<<src_path>>/ParametersDialog.h"
ParametersDialog::ParametersDialog(QWidget *parent): QDialog(parent) {
...
notify("TEST TEST 1 2 1 2", "green");
}
...
void ParametersDialog::notify(string message, string color = "red") {
notificationLabel->setText("<font color=" + color + ">" + message + "</font>");
}
Не разбирам защо ми дава тази грешка:
D:\dev\_MyCode\SM_Streamer\<<src_path>>\ParametersDialog.cpp:65:79: error: no matching function for call to 'QLabel::setText(std::__cxx11::basic_string<char>)'
notificationLabel->setText("<font color=" + color + ">" + message + "</font>");
^
Разбирам, че моята конкатенация на низ е създала basic_string<char>
елемент, който не може да бъде зададен като QLabel
текст.
Каква може да бъде най-простата реализация на моя notify
метод?
basic_string<char>
е простоstd::string
, но методът вземаQString
- person 463035818_is_not_a_number   schedule 26.05.2020notificationLabel->setText(QString("<font color=" + color + ">" + message + "</font>"));
- person 0009laH   schedule 26.05.2020QString
не може да се изгради като мен :) Благодаря ви много - person 0009laH   schedule 26.05.2020