Reputation: 153
I want to set a placeholder text in a QLineEdit. I am using the below code to do so:
QLineEdit *q = new QLineEdit;
q->setPlaceholderText("Enter number");
But on executing, the placeholder does not set. What may be the problem here?
Upvotes: 6
Views: 11547
Reputation: 8399
As the isolated code you have provided is not enough to give us a clue where the problem is, I suggest you to try this minimalistic example, see if it works for you and adapt it for your purpose. If the adaptation does not work, then post the changes you have made to discuss them.
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QLineEdit>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
};
#endif // MAINWINDOW_H
MainWindow.cpp
#include "MainWindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
QLineEdit *q = new QLineEdit(this);
q->setPlaceholderText("Enter number");
setCentralWidget(q);
}
Upvotes: 7