Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 366723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:39:35+00:00 2026-05-12T13:39:35+00:00

#include <QtGui> int main (int argc, char* argv[]) { QApplication app(argc, argv); QTextStream cout(stdout,

  • 0
#include <QtGui>

int main (int argc, char* argv[]) 
{ 
    QApplication app(argc, argv); 
    QTextStream cout(stdout, QIODevice::WriteOnly);     

    // Declarations of variables
    int answer = 0; 

    do {
        // local variables to the loop:
        int factArg = 0;
        int fact(1);
        factArg = QInputDialog::getInteger(0, "Factorial Calculator",
            "Factorial of:");
        cout << "User entered: " << factArg << endl;
        int i=2;
        while (i <= factArg) {
            fact = fact * i;
            ++i;
        }
        QString response = QString("The factorial of %1 is %2.\n%3")
            .arg(factArg).arg(fact)  
            .arg("Do you want to compute another factorial?");    
        answer = QMessageBox::question(0, "Play again?", response,
            QMessageBox::Yes | QMessageBox::No ,QMessageBox::Yes); 
    } while (answer == QMessageBox::Yes);

    return EXIT_SUCCESS;
}

In this program, i dont to have Input window(4th line of do-while loop) to have cancel button. How do i do that?
I have just started learning QT. So, sorry if its a very basic question.

And also how do i make use of cancel button to stop the application.. Bcos, right now CANCEL button does nothing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:39:35+00:00Added an answer on May 12, 2026 at 1:39 pm

    QInputDialog is given as a convenience class that provides a quick and easy way to ask for an input and as such, does not allow for much customization. I don’t see anything in the documentation to indicate that you can change the layout of the window. I would suggest just designing your own dialog by extending QDialog. This will take more time, but will allow you to customize the form.

    If you do want to determine if the cancel button was pressed in the QInputDialog, you must pass a pointer to a bool into the getInteger() function as the 8th argument.

    do{
        bool ok;
        factArg = QInputDialog::getInteger(0, "Factorial Calculator", "Factorial of:",
                                           value, minValue, maxValue, step, &ok);
        if(!ok)
        {
            //cancel was pressed, break out of the loop
            break;
        }
        // 
        // Do your processing based on input 
        //
    } while (some_condition);
    

    If ok returns as false, the user clicked cancel and you can break out of your loop. You can see what value, minValue, maxValue, and step mean in the documentation:
    QInputDialog documentation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 172k
  • Answers 172k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer git log --pretty=format:"%h%x09%an%x09%ad%x09%s" does the job. This outputs: fbc3503 mads… May 12, 2026 at 2:28 pm
  • Editorial Team
    Editorial Team added an answer malloc can segfault for example when the heap is corrupted.… May 12, 2026 at 2:28 pm
  • Editorial Team
    Editorial Team added an answer I think this should work: $("div:not(#tools)").find(".dd-container").hide(); edit: Think I mis-read… May 12, 2026 at 2:28 pm

Related Questions

I am having a qt question. I want the QLineEdit widget to have the
Alright, I have a really basic QStandardItemModel , filled with some numbers. I managed
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits
#include <iostream> using namespace std; int main() { double u = 0; double w

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.