[SOLVED]Hello World One Button, One textLabel



  • 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!


  • Moderators

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



  • 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


  • Moderators

    Cheers, happy further coding :)



  • 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



  • 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



  • 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


  • Moderators

    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.



  • 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



  • 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!



  • 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.



  • 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


  • Moderators

    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.



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.