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! is there errors in codes copied from book ?
QtWS25 Last Chance

Help! is there errors in codes copied from book ?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 6 Posters 2.8k 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.
  • S Offline
    S Offline
    shadowfox
    wrote on last edited by
    #1

    I'm a total greenhand on qt,and I lent some books form library. I copied the "helloworld" code from the book to my QTcreator, and it ran perfectly. But when I started to build some more conplex code copied from the book, it start to make errors.
    this is the code:
    @
    //addressbook.h

    #ifndef ADDRESSBOOK_H
    #define ADDRESSBOOK_H

    #include <QWidget>

    class QLineEdit;

    class AddressBook : public QWidget
    {
    Q_OBJECT
    public:
    AddressBook(QWidget *parent = 0);
    private:
    QLineEditor * nameline;
    QTextEditor * addresstext;
    };

    #endif // ADDRESSBOOK_H
    @
    It said the "QLineEditor" (and lots of other things) need declaeration in the scope. Is there missing some lib or header?

    Edit: please use @ tags around code sections; Andre

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      In the adressbook.cpp file you should also use:

      #include <QLineEdit>

      Google for Forward declaration to understand why.

      Please add @ code tags on your code. See the button with <> on it on top of the editor here.

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        You must include QLineEdit and other which you use
        @#include <QLineEdit>@

        Edit:
        As Eddy says. I'm late little bit :)

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          It is spelled QLineEdit, not QLineEditor. In addition, you are missing a forward declaration for QTextEdit in your .h file.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            [quote author="qxoz" date="1322203431"]You must include QLineEdit and other which you use
            #include <QLineEdit>[/quote]

            As long as you just use pointers a forward declaration is sufficient. There is no need to include headers.

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

              [quote author="Lukas Geyer" date="1322203500"]
              As long as you just use pointers a forward declaration is sufficient. There is no need to include headers.[/quote]

              In fact, in most cases it's good practice to not include the header where a forward declaration is sufficient. Speeding up compile time is only one of the advantages.

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

              1 Reply Last reply
              0
              • S Offline
                S Offline
                shadowfox
                wrote on last edited by
                #7

                [quote author="Lukas Geyer" date="1322203450"]It is spelled QLineEdit, not QLineEditor. In addition, you are missing a forward declaration for QTextEdit in your .h file.[/quote]

                I think that's the point. the reason i include qlineedit is it said something is not decleared. there is no include qlineedit on the book.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  Samples in books often ommit includes for classes provided by well-known libraries for the sake of brevity. Often, you can download the samples as working source code, and there the needed includes will be there.

                  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