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]Hello World One Button, One textLabel
QtWS25 Last Chance

[SOLVED]Hello World One Button, One textLabel

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 7.1k 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.
  • A Offline
    A Offline
    annis3
    wrote on 24 Aug 2012, 06:04 last edited by
    #1

    Win 7
    Qt 4

    I have a very difficult and involved project here, you understand! ;)

    Seriously, I couldn't get this to work. Here is what I did.

    First i followed the tutorial for TextFinder. It built and ran find. It loaded the text file I created. But when I typed in a word in the text to "find" I just got zilch in the text box.

    Since that was a failure I decided to try a hello world application and use something of what I had learned in TextFinder.

    Couldn't find anything about building an hello world project with widgets so I decided it couldn't be too difficult. so I followed the textfinder project. Unfortunately The compiler output this msg:
    bq.
    C:\Qt\examples\HelloWorld-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug..\HelloWorld\helloworld.cpp:-1: In member function 'void helloworld::on_hi_clicked()':

    C:\Qt\examples\HelloWorld-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug..\HelloWorld\helloworld.cpp:19: error: 'TextLabel' was not declared in this scope

    bq.
    It appears that I am going to have to declare TextLabel somewhere in order to get it to work. Here is my helloworld.h file.

    @#ifndef HELLOWORLD_H
    #define HELLOWORLD_H

    #include <QWidget>

    namespace Ui {
    class helloworld;
    }

    class helloworld : public QWidget
    {
    Q_OBJECT

    public:
    explicit helloworld(QWidget *parent = 0);
    ~helloworld();

    private slots:
    void on_hi_clicked();

    private:
    Ui::helloworld *ui;
    };

    #endif // HELLOWORLD_H@

    Here is the file helloworld.cpp I added the last 2 includes since they were in TextFinder.

    @#include "helloworld.h"
    #include "ui_helloworld.h"
    #include <QtCore/QFile>
    #include <QtCore/QTextStream>
    helloworld::helloworld(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::helloworld)
    {
    ui->setupUi(this);
    }

    helloworld::~helloworld()
    {
    delete ui;
    }

    void helloworld::on_hi_clicked()
    {
    TextLabel->setPlainText("Hello World");
    }
    @

    Thanks in Advance for your help!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 24 Aug 2012, 06:43 last edited by
      #2

      Try this in 19. line of your code:
      @
      ui->TextLabel->setPlainText("Hello World");
      @

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        annis3
        wrote on 24 Aug 2012, 07:04 last edited by
        #3

        Hi. Thanks! I finally did get it to work! Actually there were three mistakes. Textlabel wasn't in the scope untill I added ui like you suggested and 2nd it should have been label, not TextLabel. 3rd, it should have ben just setText and not setPlainText. But I wouldn't have found the others if you hadn't pointed out ui for me!
        Thanks,
        Paul

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 24 Aug 2012, 07:06 last edited by
          #4

          Cheers, happy further coding :)

          (Z(:^

          1 Reply Last reply
          0
          • C Offline
            C Offline
            CreMindES
            wrote on 24 Aug 2012, 07:06 last edited by
            #5

            And I hope that you've created a QTextLabel TextLabel and a QPushButton hi ;)
            I'm sure that there are a few Hello World example. One can be found in Qt Creator, if you'd installed examples and there are 1-2 here in the Wiki aswell. For example: "Hello World example":http://qt-project.org/wiki/Qt_for_beginners_Hello_World

            1 Reply Last reply
            0
            • A Offline
              A Offline
              annis3
              wrote on 24 Aug 2012, 14:41 last edited by
              #6

              Thanks again. The link you showed Was very basic. Also harder than most beginners would do for an introduction to Qt's GUI features it doesn't encourage the beginner and show how easy it is to create a program with it. I know most proficient programmers would think my example too easy and not worth the effort. You have to crawl before you can walk, you can't even toddle first. I would like to to put forth my example to the Qt world as a first tutorial where most of the files are created automatically. The example I followed from the help file there was obviously something wrong there because it was a bit too complicated. If a beginner has complete success with his very first program he will be more encouraged to learn all about what's in the necessary files that go to make up the typical gui program.
              I wonder where I could place it so that other frustrated beginners could see it?
              Thanks,
              Annis

              1 Reply Last reply
              0
              • A Offline
                A Offline
                annis3
                wrote on 24 Aug 2012, 19:11 last edited by
                #7

                Uh oh Problems in Qt Land! The program runs fine in Qt but when I try to run the exe file by it self, I get this error: The program can't start because mingwm10.dll is missing from your computer. Try reinstalling the program to fix this program.

                Well When I re-installed it I still get this error. :(
                Thanks,
                Paul

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sierdzio
                  Moderators
                  wrote on 24 Aug 2012, 19:24 last edited by
                  #8

                  You need to copy the .dll into the same directory your .exe is in. That's not exactly Qt's problem, it's window's nastiness. Probably, I'm not an expert on Windows.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    annis3
                    wrote on 24 Aug 2012, 20:24 last edited by
                    #9

                    MM... Can't blame that one on windows! I did a little searching and probing. All the files I needed were in the path c:\QtSDK\qt\4.8.0\mingw\bin\ There were 4 that were missing. For the record:

                    mingwm10.dll
                    libgcc_s_dw2-1.dll
                    QtCore4.dll
                    QtGui4.dll

                    Why Qt did not copy them to the release and debug dir's I don't know. I'm not interested in whose fault it was, but how to fix it. I could get to like Qt. It reminds me of C++ builder without the price tag.

                    I've been reading something about a static build. Would that package all the files I need in to one executable? If so that's where I need to go.
                    How does one do a static build in QT?
                    Thanks,
                    Annis

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      scroverty
                      wrote on 24 Aug 2012, 20:58 last edited by
                      #10

                      If you do a static build, then when you want some complex plugins with your program, It wonn't funtion.

                      But for simple app, then it might just do the job faster. Just do exactly what this "doc":http://qt-project.org/doc/qt-4.8/deployment-windows.html say, and you're on your way!

                      Alvis Ar'Berkeley Andrew.
                      Pleased to meet you!

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        annis3
                        wrote on 24 Aug 2012, 21:40 last edited by
                        #11

                        I just read that. It seems to me to many steps, too much room for errors and have to build a completely new version of Qt! I think I will just package the files i need, those 4 dlls to be sure, into an executable zip. Who ever opens the file into a dir of their choosing could create a shortcut to the exe and place it where they want. I don't know. When I start working with databases, that might not work.

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          annis3
                          wrote on 25 Aug 2012, 03:12 last edited by
                          #12

                          UPDATE:
                          Got another thought. Would it be possible to "include" those 4 files in a one of the cpp files or the header? If that isn't possible how about as resources?
                          Thanks,
                          Annis

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            sierdzio
                            Moderators
                            wrote on 25 Aug 2012, 07:36 last edited by
                            #13

                            I think Win has "LIB" environment variable that you could set, if you really want to. What most people really do, is just to copy those DLLs manually.

                            You can take a look into Qt Creator's Run Environment (in Projects pane) to see how it's done there.

                            (Z(:^

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              annis3
                              wrote on 25 Aug 2012, 19:01 last edited by
                              #14

                              I think just to pack everything in a zip or an executable zip would be OK for now. Well Thanks everyone for heling out!
                              Annis

                              1 Reply Last reply
                              0

                              8/14

                              24 Aug 2012, 19:24

                              • Login

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