Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] How do I use Creator with C++?

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.4k Views
  • 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 Offline
    E Offline
    Endless
    wrote on last edited by
    #1

    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
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      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
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        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
        0
        • U Offline
          U Offline
          ucomesdag
          wrote on last edited by
          #4

          [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
          0
          • E Offline
            E Offline
            Endless
            wrote on last edited by
            #5

            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
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #6

              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
              0
              • E Offline
                E Offline
                Endless
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on last edited by
                  #8

                  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
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved