Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] *ui not recognized
Qt 6.12 LTS is out! See what's new in the release blog

[Solved] *ui not recognized

Scheduled Pinned Locked Moved General and Desktop
18 Posts 3 Posters 6.2k 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.
  • JohanSoloJ Offline
    JohanSoloJ Offline
    JohanSolo
    wrote on last edited by JohanSolo
    #9

    As SGaist said, every object deriving from QObject cannot be copied, your function must therefore be:

    void writeErrorMsg(MainForm& window, QString msg, int value);
    

    or

    void writeErrorMsg(MainForm* window, QString msg, int value);
    

    In your function you're (maybe wihout knowing it) making a copy of the window variable, which is then used in the function's body. Since copying a QObject is impossible by design you're not allowed to use this kind of syntax.

    Edit: you can have a look at this to get an overview of how you can pass parameters to a function

    `They did not know it was impossible, so they did it.'
    -- Mark Twain

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #10

      Thank you for your explanations.

      I changed it everywhere but the same errors remain. They are all focalised on the use of MainForm in the function writeErrorMsg. I guess that I still don't use it well

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #11

        Can you show the latest version of your code ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #12

          Sure. I put everything.

          mainform.h:

          @#ifndef MAINFORM_H
          #define MAINFORM_H

          #include "ui_mainform.h"
          #include <QMainWindow>
          #include <QString>
          #include <iostream>
          #include <QTextEdit>

          namespace Ui {
          class MainForm;
          }

          class MainForm : public QMainWindow
          //private Ui::MainForm
          {
          Q_OBJECT

          public:
          explicit MainForm(QWidget *parent = 0);
          ~MainForm();
          void insertTextInErrorBrowser(QTextEdit *line);

          private:
          Ui::MainForm *ui;
          };

          #endif@

          mainform.cpp:
          @
          #include <QtGui>
          #include "mainform.h"

          MainForm::MainForm(QWidget *parent)
          : QMainWindow(parent),
          ui(new Ui::MainForm)
          {
          ui->setupUi(this);
          ui->errorBrowser->setText("hello");
          }

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

          void MainForm::insertTextInErrorBrowser(QTextEdit *line)
          {
          connect(line, SIGNAL(textChanged(QString)), ui->errorBrowser, SLOT(insertPlainText(QString)));
          }@

          errorMsg.h:

          @#include "mainform.h"

          #ifndef ERRORMSG_H
          #define ERRORMSG_H

          class errorMsg : public QObject
          {
          //Q_OBJECT

          public:
          errorMsg();
          ~errorMsg();
          void writeErrorMsg(MainForm& window, QString msg, int value);
          };

          #endif@

          errorMsg.cpp:

          @#include "errorMsg.h"

          errorMsg::errorMsg()
          {}

          errorMsg::~errorMsg()
          {}

          void errorMsg::writeErrorMsg(MainForm& window, QString msg, int value)
          {
          QTextEdit *line = new QTextEdit("Hello2");
          QColor colorLine;
          QFont bold;
          bold.setBold(true);

          if (value==1)
          {
          colorLine.setRgb(191,13,9);
          line->setTextColor(colorLine);
          line->setFont(bold);
          }
          else ... (idem)

          line->setReadOnly(true);
          window.insertTextInErrorBrowser(line);
          }@

          main.h:

          @#include <QApplication>
          #include "errorMsg.h"

          int main(int argc, char *argv[])
          {
          QApplication app(argc, argv);

          MainForm window;
          errorMsg error;
          error.writeErrorMsg(window, "coucou", 2);
          window.show();

          return 0;
          }@

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #13

            Your logic is pretty strange, you are creating a read-only QLineEdit and connect it to your errorBrowser. Line edit that will not be shown and never be released.

            What is it that you want to achieve ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #14

              Yes the ReadOnly for "line" is useless because the browser is ReadOnly already. My logic is just to make all the changes about the line before and insert it simply in the QTextEdit errorBrowser

              What I would like is creating a errorBrowser which can display some defined errors, and also I need to insert a "line" into it.

              The errorBrowser is shown thanks to my ui_mainform.h and main.h files, so I thought that the inserted "line" was shown too, right?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #15

                Then you should have an error class that represent only the error and that returns the corresponding string (e.g. a lighter version of the QSqlError class)

                Why do you need that additional line ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #16

                  I use that line because I have to change the writing style before inserting it in the browser (after it is too late). I don't think that I can change the colour and style of the written text directly in my connect to my browser, or maybe it is possible but I don't know how..

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #17

                    Then you should have a look at QTextDocument to see how you can modify blocks of text to show how you want

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #18

                      I found another way: I put my writeErrorMsg function in my mainform files instead of in my errorMsg files, and it works fine now! Thank you for your advises

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