Pages
API Documentation
On this page

KNSCore::Question Class

A way to ask a user a question from inside a GUI-less library (like KNewStuffCore). More...

  • Header: #include <Question>
  • CMake: find_package(KF6 REQUIRED COMPONENTS NewStuff)
    target_link_libraries(mytarget PRIVATE KF6::NewStuff)
  • Inherits: QObject

List of all members, including inherited members

Public Types

Public Functions

Detailed Description

Rather than using a message box (which is a UI thing), when you want to ask your user a question, create an instance of this class and use that instead. The consuming library (in most cases KNewStuff or KNewStuffQuick) will listen to any question being asked, and act appropriately (that is, KNewStuff will show a dialog with an appropriate dialog box, and KNewStuffQuick will either request a question be asked if the developer is using the plugin directly, or ask the question using an appropriate method for Qt Quick based applications)

The following is an example of a question asking the user to select an item from a list.

QStringList choices() << "foo" << "bar";
Question question(Question::SelectFromListQuestion);
question.setTitle("Pick your option");
question.setQuestion("Please select which option you would like");
question.setList(choices);
question.setEntry(entry);
if (question.ask() == Question::OKResponse) {
    QString theChoice = question.response();
}

Member Type Documentation

enum Question::QuestionType

Defines the type of question to be presented to the user.

Constant Value Description
KNSCore::Question::YesNoQuestion 0 The question can be answered with either yes or no.
KNSCore::Question::ContinueCancelQuestion 1 The question can be answered with either continue or cancel.
KNSCore::Question::InputTextQuestion 2 Answering the question requires text input from the user.
KNSCore::Question::SelectFromListQuestion 3 Answering the question requires selecting from a list of choices.
KNSCore::Question::PasswordQuestion 4 Answering the question requires the user to input a password.

See also Response

enum Question::Response

Defines how the user responded to the question.

Constant Value Description
KNSCore::Question::InvalidResponse 0 The user did not provide a valid response.
KNSCore::Question::YesResponse 1 The user selected yes.
KNSCore::Question::NoResponse 2 The user selected no.
KNSCore::Question::ContinueResponse 3 The user selected continue.
KNSCore::Question::CancelResponse 4 The user selected cancel.
KNSCore::Question::OKResponse YesResponse The user selected OK.

See also QuestionType

Member Function Documentation

KNSCore::Question::Response Question::ask()

Returns the user's reponse to the question.

See also setResponse

KNSCore::Entry Question::entry() const

Returns the configured entry.

See also setEntry()

QStringList Question::list() const

Returns the list of choices to present to the user, if any.

See also setList()

QString Question::question() const

Returns the question message to be presented to the user.

See also setQuestion()

KNSCore::Question::QuestionType Question::questionType() const

Returns the configured question type.

See also setQuestionType()

QString Question::response() const

Returns the response data provided by the user, if any.

See also setResponse()

void Question::setEntry(const KNSCore::Entry &entry)

Sets the data entry container this question refers to.

See also entry()

void Question::setList(const QStringList &newList)

Sets the list of optional choices to present to the user to newList for a SelectFromListQuestion.

See also list()

void Question::setQuestion(const QString &newQuestion)

Sets the question to be presented to the user.

newQuestion is the question message

See also question()

void Question::setQuestionType(KNSCore::Question::QuestionType newType = YesNoQuestion)

Sets the type of question presented to the user.

newType is the question type

See also questionType()

void Question::setResponse(KNSCore::Question::Response response)

When the user makes a choice on a question, that is a response. This is the return value in ask().

response This will set the response, and mark the question as answered

See also response()

void Question::setResponse(const QString &response)

If the user has any way of inputting data to go along with the response above, consider this a part of the response. As such, you can set, and later get, that response as well. This does NOT mark the question as answered.

response This sets the string response for the question

See also setResponse

void Question::setTitle(const QString &newTitle)

Sets the title of the UX element presented to the user.

newTitle is the title text

See also title()

QString Question::title() const

Returns the title of the UX element.

See also setTitle()

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.