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. Help with QTextEdit.
Forum Updated to NodeBB v4.3 + New Features

Help with QTextEdit.

Scheduled Pinned Locked Moved General and Desktop
28 Posts 4 Posters 14.6k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    MASTER260
    wrote on last edited by
    #1

    So, I'm trying to follow this tutorial in Visual C++ 2010, only the only thing I would say is, "Hello World!"

    http://wiki.forum.nokia.com/index.php/How_to_use_QSplitter_and_QTextEdit_in_Qt

    I recreated the splitter.h from here since it appears to need that:
    http://stackoverflow.com/questions/3888611/qt-separator-widget

    ...&, of course, it's not working. Anyone wanaa help? You can download the source here:
    http://www.4shared.com/file/z-W7FIJF/Project_Is_This_a_Bad_Game.html

    Thank you,
    M260

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      First a hint for posting:

      Thanks for providing the source code, it helps in searching the problem. But please do not include object and build files for your platform/compiler/IDE. Your download is about 18 MB, which is quite big for four sources files in the end ;-)

      It makes your life much more easier and will most probably lead to more people reading your post and thinking about your problem.

      So, regarding your actual problem. This is nothing directly Qt related, more sort of some general issues with C++. I suppose you are new to C++, as these kind of errors are very common, every programmer stumbles over them once in a while, even the most skilled ones.

      I'll post the code here to ease the analysis:

      --- splitter.h ---

      @
      #ifndef SPLITTER_H
      #define SPLITTER_H

      #include <QtGui/QDialog>

      class splitter : public QDialog
      {
      Q_OBJECT;

      QWidget*        widget1;
      QWidget*        widget2;
      
      QPushButton*    button;
      

      public:
      splitter(QWidget *parent = 0, Qt::WFlags flags = 0);
      ~splitter();

      private slots:
      void showHide(void);
      };

      #endif // SPLITTER_H
      @

      --- projectisthisabadgame.cpp ---

      @
      #include "projectisthisabadgame.h"
      #include "splitter.h"
      #include<QSplitter>
      #include<QTextEdit>
      #include<QHBoxLayout>

      ProjectIsThisaBadGame::ProjectIsThisaBadGame(QWidget *parent, Qt::WFlags flags)
      : QMainWindow(parent, flags)
      {
      ui.setupUi(this);
      }

      ProjectIsThisaBadGame::~ProjectIsThisaBadGame()
      {

      }

      splitter::splitter(QWidget *parent)
      : QWidget(parent)
      {
      QHBoxLayout *layout=new QHBoxLayout(this);
      QTextEdit editor1 = new QTextEdit("Hello World",this);QSplitter splitter(Qt::Vertical);
      splitter.addWidget(editor1);
      layout->addWidget(editor1);
      setStyleSheet("
      { background-color:rgb(0,0,0);color:rgb(255,255,255); padding: 7px}}");

      setLayout(layout);
      showMaximized();
      }
      @

      You have several errors here, I post the messages from gcc (on a Mac). You are on Windows using Visual Studio, so the error messages are different, but should be worded similar.

      bq. projectisthisabadgame.cpp:18: Error:prototype for 'splitter::splitter(QWidget*)' does not match any in class 'splitter'

      Look at the declaration of the constructor in splitter.h line 16:

      @
      splitter(QWidget *parent = 0, Qt::WFlags flags = 0);
      @

      and compare with the signature of the constructor you actually implemented in projectisthisabadgame.cpp:

      @
      splitter::splitter(QWidget *parent)
      : QWidget(parent)
      {
      // ...
      }
      @

      You see: you declared a constructor with two parameters, but implemented it with only one parameter. You can add the second parameter in the .cpp or remove the second one in the .h. Go with the first, as this is the same signature as the standard constructor of "QDialog":http://doc.qt.nokia.com/4.7/qdialog.html#QDialog.

      This ist the correct constructor signature:

      @
      splitter::splitter(QWidget *parent, Qt::WFlags flags)
      : QWidget(parent)
      {
      // ...
      }
      @

      Another compiler run gives us the next error message:

      bq. projectisthisabadgame.cpp:19: Error:type 'class QWidget' is not a direct base of 'splitter'

      This is easy to fix, too. In splitter.h you declared class splitter to inherit from QDialog. In the implementation you call a QWidget constructor (which is a base class of QDialog; line 19 in projectisthisabadgame.cpp). But this is wrong, you must always call the constructors of the direct base class in your own constructors. So, change this to:

      @
      splitter::splitter(QWidget *parent, Qt::WFlags flags)
      : QDialog(parent, flags)
      {
      // ...
      }
      @

      Also, notice the handing over of the second parameter (flags) to QDialog's constructor.

      Your code now compiles without errors. The next errors are popped up by the linker (which does not compile anything, but puts the previously compiled little pieces together to the final application).

      bq. Undefined symbols: splitter::~splitter() and splitter::showHide()

      In your splitter.h you declared a destructor ~splitter() (line 17) and a method showHide() (line 20), but you did not provide an implementation in your .cpp file. Just add some dummy implementation in the .cpp:

      @
      splitter::~splitter()
      {
      }

      void splitter::showHide()
      {
      }
      @

      Please note that a parameter-less method takes no argument. It's not an error to write showHide(void), but most programmers consider this as unnecessary chatter. Better omit it.

      Your code now compiles and links without errors.

      Just another tip: In your project you have splitter.h and projectisthisabadgame.h declaring the classes. You implement both in projectisthisabadgame.cpp. This works, no question, but it is not a good idea. Better to separate your classes' implementations into separate files too (i.e. move the splitter stuff into a new file splitter.cpp)

      Feel free to come back with further questions.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MASTER260
        wrote on last edited by
        #3

        Thank you! :D

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MASTER260
          wrote on last edited by
          #4

          Sry, but I seem to get a, "cannot open file, 'QTHelpd4.lib,'" error, even after compiling Qt from source...

          Help please!

          Thank you :D
          M260

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            Did you add

            @
            CONFIG += help
            @

            to your .pro file?

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MASTER260
              wrote on last edited by
              #6

              Thanks, I'll try it!

              EDIT: Well, you see, I'm pretty sure Visual Studio uses plain ol' cpp files instead of pro files, just like normal C++. So, I added it to the end of projectisthisabadgame.cpp & got this output:

              @1>------ Build started: Project: Project Is This a Bad Game, Configuration: Debug Win32 ------
              1>Build started 4/17/2011 10:32:12 AM.
              1>InitializeBuildStatus:
              1> Touching "Debug\Project Is This a Bad Game.unsuccessfulbuild".
              1>CustomBuild:
              1> All outputs are up-to-date.
              1>ClCompile:
              1> projectisthisabadgame.cpp
              1>projectisthisabadgame.cpp(39): error C2143: syntax error : missing ';' before '+='
              1>projectisthisabadgame.cpp(39): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
              1>
              1>Build FAILED.
              1>
              1>Time Elapsed 00:00:03.26
              ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========@

              Can anyone help?

              Thanks,
              M260

              1 Reply Last reply
              0
              • A Offline
                A Offline
                azr79
                wrote on last edited by
                #7

                Show us your projectisthisabadgame.cpp please, in particulary from line 37 - 40

                Azr79

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

                  Well, actually, an old version is shown earlier in this thread, but here's an updated version:

                  @#include "projectisthisabadgame.h"
                  #include "splitter.h"
                  #include<QSplitter>
                  #include<QTextEdit>
                  #include<QHBoxLayout>

                  ProjectIsThisaBadGame::ProjectIsThisaBadGame(QWidget *parent, Qt::WFlags flags)
                  : QMainWindow(parent, flags)
                  {
                  ui.setupUi(this);
                  }

                  ProjectIsThisaBadGame::~ProjectIsThisaBadGame()
                  {

                  }

                  splitter::splitter(QWidget *parent, Qt::WFlags flags)
                  : QDialog(parent, flags)
                  {
                  QHBoxLayout *layout=new QHBoxLayout(this);
                  QTextEdit editor1 = new QTextEdit("Hello World",this);QSplitter splitter(Qt::Vertical);
                  splitter.addWidget(editor1);
                  layout->addWidget(editor1);
                  setStyleSheet("
                  { background-color:rgb(0,0,0);color:rgb(255,255,255); padding: 7px}}");

                  setLayout(layout);
                  showMaximized();
                  }

                  splitter::~splitter()
                  {
                  }

                  void splitter::showHide()
                  {
                  }

                  CONFIG += help@

                  EDIT: Um, the forum messed up the formatting a bit I think, but, whatever...

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    azr79
                    wrote on last edited by
                    #9

                    Line 39!!!!

                    @CONFIG += help@

                    got to be removed from this file and add it into your .pro file, try to recompile then.

                    Azr79

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      MASTER260
                      wrote on last edited by
                      #10

                      But the reason I added it there is because it seems Visual Studio doesn't support pro files...

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        azr79
                        wrote on last edited by
                        #11

                        I think that you got to generate it with qmake.exe and add it in your links, i'll search more infos for later, stand by mate

                        Azr79

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #12

                          You can use the "Visual Studio Add-in":http://qt.nokia.com/downloads/visual-studio-add-in to manage the mapping between .pro files and Visual Studio project files. The manual is "here":http://doc.qt.nokia.com/vs-add-in-1.1.7/index.html.

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            azr79
                            wrote on last edited by
                            #13

                            OK, here is the deal:
                            You have to generate a .pro file with 'Qt command prompt' (look into qt root folder)
                            Start Qt Command prompt and enter following commands:

                            -> cd c:\Folder\of\your\project\ (directory that contains Visual studio's project file)
                            -> qmake -project
                            -> qmake

                            after these commands look into your project folder, you'll see some auto generated files and folders, and .pro file will be there, just edit it however you want.

                            If you want to compile just continue with the following command:
                            -> make

                            Azr79

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              MASTER260
                              wrote on last edited by
                              #14

                              Thanks, but after doing qmake, this happened:

                              http://i55.tinypic.com/ivzpcp.png

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                goetz
                                wrote on last edited by
                                #15

                                A couple of warnings - nothing to worry about. What happens after running nmake?

                                http://www.catb.org/~esr/faqs/smart-questions.html

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  azr79
                                  wrote on last edited by
                                  #16

                                  Is your project compiled?

                                  By the way, use preferably directories without spaces for your projects, very important!
                                  Ex.: c:\Dev\Qt_Projects\This_is_a_very_bad_game
                                  Never use spaces, compilator might show you some errors.

                                  Azr79

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    MASTER260
                                    wrote on last edited by
                                    #17

                                    [quote author="Azr79" date="1303931305"]Is your project compiled?

                                    By the way, use preferably directories without spaces for your projects, very important!
                                    Ex.: c:\Dev\Qt_Projects\This_is_a_very_bad_game
                                    Never use spaces, compilator might show you some errors.[/quote]

                                    Well, it's never compiled succesfully since everything in ths thread's happened... (Not to be rude.)

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      azr79
                                      wrote on last edited by
                                      #18

                                      why not using QtCreator? There is no problems with it, because already configured for qt projects....

                                      Azr79

                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        MASTER260
                                        wrote on last edited by
                                        #19

                                        [quote author="Azr79" date="1303944734"]why not using QtCreator? There is no problems with it, because already configured for qt projects....[/quote]
                                        The problem is it doesn't seem to be friendly with what I'm trying to do.

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          giesbert
                                          wrote on last edited by
                                          #20

                                          Do you have your old vcproj file stored somewhere?
                                          If you want to add a lib in MSVS, use the MSVS way, even for Qt libs:

                                          open project settinbs, go to linker --> input page and add the file

                                          Nokia Certified Qt Specialist.
                                          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                          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