Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] How do I use Creator with C++?

    General and Desktop
    4
    8
    2061
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      Endless last edited by

      I've recently started using Qt Creator 2.2.1. I've had no problem going through the first few modules in Qt Quick for Designers, but everything's in QML.

      What I'm trying to do now is develop something, anything in C++. I've seen the short Hello World program in several places and have tried to get it to work. If you aren't familiar, here's the program:

      @#include <QtGui/QApplication>
      int main(int argc, char argv[])
      {
      QApplication app(argc, argv);
      QPushButton
      button = new QPushButton("Hello There");
      button->show();
      return app.exec();
      }@

      This is as simple as it gets, but I can't get it to run in Creator. I've created a new project using Qt Quick Project -> Qt Quick Application. I get an error on the #include statement.

      1 Reply Last reply Reply Quote 0
      • E
        Eddy last edited by

        What is the error you get? We don't have a christal ball you know ;)

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply Reply Quote 0
        • M
          mlong last edited by

          At a minimum, in the the example you gave, you'll want to add
          @
          #include <QtGui/QPushButton>
          @

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply Reply Quote 0
          • U
            ucomesdag last edited by

            [quote author="Endless" date="1312912624"]I've created a new project using Qt Quick Project -> Qt Quick Application. I get an error on the #include statement.[/quote]
            There is your error, use Qt Widget Project -> Qt Gui Application

            Write “Qt”, not “QT” (QuickTime).

            1 Reply Last reply Reply Quote 0
            • E
              Endless last edited by

              Apparently the additional include statement got me what I needed. Thanks so much for the help. One last question, though: I thought when I clicked on the button, it would terminate the application. I can click it as many times as I want, but the app doesn't end.

              1 Reply Last reply Reply Quote 0
              • M
                mlong last edited by

                You don't have any action tied to the button's clicked() signal.

                After you create the button, you'll want to add
                @
                QObject::connect(button, SIGNAL(clicked(), &app, SLOT(quit()));
                @
                to connect button's clicked() signal to the application's quit() slot.

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                1 Reply Last reply Reply Quote 0
                • E
                  Endless last edited by

                  Yes, mlong, that did it. Thanks for the help.

                  1 Reply Last reply Reply Quote 0
                  • M
                    mlong last edited by

                    Glad to help! Be sure to edit the thread title and add [Solved] to the beginning! Thanks!

                    Software Engineer
                    My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post