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. Widget copy problem
Forum Updated to NodeBB v4.3 + New Features

Widget copy problem

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 7.3k 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.
  • X Offline
    X Offline
    Xentrum
    wrote on last edited by
    #1

    Hello,
    In my application, i need to get one widget from a QList and add it into a layout. So i have : @layout->addWidget(myList.at(i));@ .

    After modifiying my code in
    @layout->addWidget(new QLabel(myList.at(i).text()));@

    i've got some critical error : @In file included from ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qobject.h:50,
    from ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qabstractanimation.h:45,
    from ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/QtCore:3,
    from ....\Qt\Desktop\Qt\4.8.1\mingw\include\QtGui/QtGui:3,
    from ..\CSS_Explicit/mainwidget.h:4,
    from ..\CSS_Explicit\mainwidget.cpp:1:
    ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtGui/qlineedit.h: In member function 'void QList<T>::node_construct(QList<T>::Node*, const T&) [with T = QLineEdit]':
    ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:512: instantiated from 'void QList<T>::append(const T&) [with T = QLineEdit]'
    ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:334: instantiated from 'QList<T>& QList<T>::operator<<(const T&) [with T = QLineEdit]'
    ..\CSS_Explicit\mainwidget.cpp:11: instantiated from here
    ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtGui/qlineedit.h:279: error: 'QLineEdit::QLineEdit(const QLineEdit&)' is private
    ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:372: error: within this context
    ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtGui/qlineedit.h:279: error: 'QLineEdit::QLineEdit(const QLineEdit&)' is private
    ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:373: error: within this context
    ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtGui/qlineedit.h:279: error: 'QLineEdit& QLineEdit::operator=(const QLineEdit&)' is private@

    1 Reply Last reply
    0
    • X Offline
      X Offline
      Xentrum
      wrote on last edited by
      #2

      @....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:378: error: within this context
      ....\Qt\Desktop\Qt\4.8.1\mingw\include\QtGui/qlabel.h: In member function 'void QList<T>::node_construct(QList<T>::Node*, const T&) [with T = QLabel]':
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:512: instantiated from 'void QList<T>::append(const T&) [with T = QLabel]'
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:334: instantiated from 'QList<T>& QList<T>::operator<<(const T&) [with T = QLabel]'
      ..\CSS_Explicit\mainwidget.cpp:13: instantiated from here
      ....\Qt\Desktop\Qt\4.8.1\mingw\include\QtGui/qlabel.h:165: error: 'QLabel::QLabel(const QLabel&)' is private
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:372: error: within this context
      ....\Qt\Desktop\Qt\4.8.1\mingw\include\QtGui/qlabel.h:165: error: 'QLabel::QLabel(const QLabel&)' is private
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:373: error: within this context
      ....\Qt\Desktop\Qt\4.8.1\mingw\include\QtGui/qlabel.h:165: error: 'QLabel& QLabel::operator=(const QLabel&)' is private
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:378: error: within this context
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtGui/qlineedit.h: In member function 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = QLineEdit]':
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:681: instantiated from 'QList<T>::Node* QList<T>::detach_helper_grow(int, int) [with T = QLineEdit]'
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:510: instantiated from 'void QList<T>::append(const T&) [with T = QLineEdit]'
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:334: instantiated from 'QList<T>& QList<T>::operator<<(const T&) [with T = QLineEdit]'
      ..\CSS_Explicit\mainwidget.cpp:11: instantiated from here
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtGui/qlineedit.h:279: error: 'QLineEdit::QLineEdit(const QLineEdit&)' is private
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:399: error: within this context
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtGui/qlineedit.h:279: error: 'QLineEdit::QLineEdit(const QLineEdit&)' is private
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:412: error: within this context
      ....\Qt\Desktop\Qt\4.8.1\mingw\include\QtGui/qlabel.h: In member function 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = QLabel]':
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:681: instantiated from 'QList<T>::Node* QList<T>::detach_helper_grow(int, int) [with T = QLabel]'
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:510: instantiated from 'void QList<T>::append(const T&) [with T = QLabel]'
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:334: instantiated from 'QList<T>& QList<T>::operator<<(const T&) [with T = QLabel]'
      ..\CSS_Explicit\mainwidget.cpp:13: instantiated from here
      ....\Qt\Desktop\Qt\4.8.1\mingw\include\QtGui/qlabel.h:165: error: 'QLabel::QLabel(const QLabel&)' is private
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:399: error: within this context
      ....\Qt\Desktop\Qt\4.8.1\mingw\include\QtGui/qlabel.h:165: error: 'QLabel::QLabel(const QLabel&)' is private
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:412: error: within this context
      ....\Qt\Desktop\Qt\4.8.1\mingw\include\QtGui/qboxlayout.h: In member function 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = QHBoxLayout]':
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:711: instantiated from 'void QList<T>::detach_helper(int) [with T = QHBoxLayout]'
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:725: instantiated from 'void QList<T>::detach_helper() [with T = QHBoxLayout]'
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:446: instantiated from 'QList<T>& QList<T>::operator=(const QList<T>&) [with T = QHBoxLayout]'
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:766: instantiated from 'void QList<T>::clear() [with T = QHBoxLayout]'
      ..\CSS_Explicit\mainwidget.cpp:15: instantiated from here
      ....\Qt\Desktop\Qt\4.8.1\mingw\include\QtGui/qboxlayout.h:146: error: 'QHBoxLayout::QHBoxLayout(const QHBoxLayout&)' is private
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:399: error: within this context
      ....\Qt\Desktop\Qt\4.8.1\mingw\include\QtGui/qboxlayout.h:146: error: 'QHBoxLayout::QHBoxLayout(const QHBoxLayout&)' is private
      ....\Qt\Desktop\Qt\4.8.1\mingw\include/QtCore/qlist.h:412: error: within this context
      mingw32-make.exe[1]: *** [debug/mainwidget.o] Error 1
      mingw32-make.exe: *** [debug] Error 2@

      All of those errors are in qt files and i can't copy/add widget to another widget !

      I need help !
      Thanks.
      Xentrum

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on last edited by
        #3

        [quote author="Xentrum" date="1339606742"]Hello,
        In my application, i need to get one widget from a QList and add it into a layout. So i have : @layout->addWidget(myList.at(i));@ .

        After modifiying my code in
        @layout->addWidget(new QLabel(myList.at(i).text()));@

        [/quote]
        Yes, If I am right, what you want it is
        @layout->addWidget(new QLabel(myList.at(i)->text()));@

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xentrum
          wrote on last edited by
          #4

          Yes. Principal error is about copying the widget : the overloaded constructor for copying QLabel/QLineEdit... Is suggested by Qt Creator but the debbuger says that this constructor is private

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

            This "link":http://qt-project.org/doc/qt-4.8/object.html#identity-vs-value can help understanding why.

            Qt Certified Specialist
            www.edalsolutions.be

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

              Copying QWidgets is inherently prohibited. (What is a "copy" of a widget supposed to include?)

              What is the purpose of your list of widgets? Would you be better off keeping a list of widget pointers?

              That way you could work without having to make copies of the widgets themselves.

              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
              • X Offline
                X Offline
                Xentrum
                wrote on last edited by
                #7

                I want to do dynamics lines with 2 QLineEdit and 1 Label. The number of lines depend of the size of my QList which is the same as two other QList. Each list contains one widget(QLineEdit/Qlabel) and i'm doing "for" loop for creating my layout :
                @for(int i = 0;i <= propertyList.size();i++){
                QHBoxLayout *layoutExample = new QHBoxLayout();
                layoutExample->addWidget(new QLabel(labelList.at(i).text()));
                layoutExample->addWidget(new QLineEdit(propertyList.at(i).text()));
                layoutExample->addWidget(new QLineEdit(valueList.at(i).text()));
                layout->addLayout(layoutExample);
                }@

                EDIT : I just recompiled my codes and even when i've deleted this part the pb stay. Maybe should i repair my Qt installation ?

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

                  So what types are the QLists of? Where do they come from? Is it sufficient for the QLists to just contain QString values for the text, rather than widgets?

                  [Edit to add:]

                  You might also consider creating a custom widget class which contains your Label and TextEntry fields. Might make things a little tidier in working with things. (Just a suggestion, though.)

                  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
                  • X Offline
                    X Offline
                    Xentrum
                    wrote on last edited by
                    #9

                    this is already a new widget. here's my complete code :
                    mainwidget.h:
                    @#ifndef MAINWIDGET_H
                    #define MAINWIDGET_H

                    #include <QtGui>

                    class MainWidget : public QWidget
                    {
                    Q_OBJECT
                    public:
                    explicit MainWidget(QWidget *parent = 0);
                    MainWidget(QString name);

                    signals:

                    public slots:

                    private:
                    QVBoxLayout *layout;
                    QString tabName;
                    QList<QLineEdit> propertyList;
                    QList<QLineEdit> valueList;
                    QList<QLabel> labelList;
                    QList<QHBoxLayout> *linePropertyList;
                    };

                    #endif // MAINWIDGET_H
                    @

                    and mainwidget.cpp :

                    @
                    #include "mainwidget.h"

                    MainWidget::MainWidget(QWidget *parent) :
                    QWidget(parent)
                    {
                    linePropertyList = new QList<QHBoxLayout>;
                    QHBoxLayout *mainlayout = new QHBoxLayout;
                    QString tabName = "New";
                    layout = new QVBoxLayout;
                    if(propertyList.isEmpty()){
                    propertyList <<QLineEdit("color");
                    valueList << QLineEdit("black");
                    labelList << QLabel(tr("Property 1"));
                    }
                    linePropertyList->clear();
                    for(int i = 0;i <= propertyList.size();i++){
                    QHBoxLayout *layoutExample = new QHBoxLayout();
                    layoutExample->addWidget(new QLabel(labelList.at(i).text()));
                    layoutExample->addWidget(new QLineEdit(propertyList.at(i).text()));
                    layoutExample->addWidget(new QLineEdit(valueList.at(i).text()));
                    layout->addLayout(layoutExample);
                    }
                    mainlayout->addLayout(layout);
                    mainlayout->addWidget(new QTextEdit());
                    setLayout(mainlayout);
                    }
                    MainWidget::MainWidget(QString name)
                    {
                    QHBoxLayout *mainlayout = new QHBoxLayout;
                    QString tabName = name;
                    layout = new QVBoxLayout;
                    mainlayout->addLayout(layout);
                    mainlayout->addWidget(new QTextEdit());
                    setLayout(mainlayout);
                    setMinimumSize(400,800);
                    }
                    @

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

                      Again, I ask...

                      Why are your lists of widgets, instead of QStrings? You only appear to be using the text values of those widgets in the lists.

                      Why not:
                      @
                      ...
                      QList<QString> propertyList; // Or QStringList propertyList;
                      QList<QString> valueList;
                      QList<QString> labelList;
                      ...
                      if(propertyList.isEmpty()){
                      propertyList <<"color";
                      valueList << "black";
                      labelList << tr("Property 1");
                      }
                      ...
                      for(int i = 0;i <= propertyList.size();i++){
                      QHBoxLayout *layoutExample = new QHBoxLayout();
                      layoutExample->addWidget(new QLabel(labelList.at(i)));
                      layoutExample->addWidget(new QLineEdit(propertyList.at(i)));
                      layoutExample->addWidget(new QLineEdit(valueList.at(i)));
                      layout->addLayout(layoutExample);
                      }
                      ...
                      @

                      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
                      • X Offline
                        X Offline
                        Xentrum
                        wrote on last edited by
                        #11

                        i tried to directly create my object in a QList. But maybe your solution is better. I'll try it. Thanks

                        1 Reply Last reply
                        0
                        • X Offline
                          X Offline
                          Xentrum
                          wrote on last edited by
                          #12

                          Now, i got another pb : because we are in a for loop, no layout is showed at the end. Do you have a solution ?

                          EDIT : In fact, there was no pb : i just forget to copy the code in my overloaded constructor

                          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