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. Old program
Forum Updated to NodeBB v4.3 + New Features

Old program

Scheduled Pinned Locked Moved General and Desktop
16 Posts 3 Posters 4.0k 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.
  • J Offline
    J Offline
    joker_hr
    wrote on last edited by
    #3

    ok so far so good, i have managed to implement classes.
    Yes you are right i dont need extra thread.
    but I have signal - slot issue
    please could someone help me with this
    my problem is that I can't update simple label from created class.
    i am looking on this like:
    when program started (mainwindow) it create instance of myclass
    then I have to pass pointer of my mainwindow class to created myclass.
    On myclass constructor connection with signal(function) are created and pointing to function in mainwindow class.

    mainwindow.h
    @
    #include <QMainWindow>
    #include <typedefs.h>
    #include <QTimer>
    namespace Ui {
    class MainWindow;
    }
    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    public slots:
    void UpdateLabels(QString text);
    private slots:
    void on_pushButton_clicked();
    ....
    void TimerEvent(); // working in class signal - slot
    private:
    Ui::MainWindow *ui;
    QTimer timer;
    };
    @
    mainwindow.cpp
    @
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include<cf7.h>

    cf7 *cf;

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    ...
    cf =new cf7(this);

    // connect(cf, SIGNAL(updateUI(const QString)), ui, SLOT(UpdateLabels(const QString)));

    cf->open();
    cf->CF_Init();
    cf->enable();
     connect(&timer, SIGNAL(timeout()), this, SLOT(TimerEvent()));
     this->timer.start(100);
    

    }

    void MainWindow::UpdateLabels(QString text) // updating function
    {
    ui->line6->setText(text);
    }
    @

    cf7.h
    @
    #include <typedefs.h>
    #include <QObject>
    ...
    #define device "/dev/ttyUSB0"

    class cf7 : public QObject{

    Q_OBJECT
    public:
    cf7(QObject *parent);
    int pooling(void);
    int openZetonjeraPort(void);
    int CF_Init(void);
    signals:
    void updateUI(QString text);
    };
    @
    cf7.cpp

    @
    #include "cf7.h"
    #include "mainwindow.h"
    #include <QDebug>
    ...
    cf7::cf7(QObject *parent)
    {
    // connect(this,SIGNAL(updateUI(QString),)
    //connect(this, SIGNAL(updateUI(QString)),parent, SLOT(UpdateLabels(QString)));
    //connect(&cf, SIGNAL(updateUI(QString)), ui, SLOT(UpdateLabels(QString)));
    }
    int cf7:: pooling(void)
    {
    ...serial stuff...
    updateUI("HELLO");
    return 0;
    }
    ...
    int cf7 :: open(void)
    {
    fz = open(device ,O_RDWR | O_NOCTTY | O_NONBLOCK);
    if (fz <0)
    {
    exit(1);
    }
    tio.c_cflag = baud | CS8 | CREAD | CLOCAL| ICRNL ;
    tio.c_oflag = 0;
    tio.c_cc[VTIME] = 0;
    tio.c_cc[VMIN] = 0;
    tcflush(fz, TCIFLUSH);
    tcsetattr(fz, TCSANOW, &tio);
    return 0;
    }
    ..
    int cf7::CF_Init(void)
    {
    ... serial stuff

    updateUI("HELLO");
    return 0;
    }

    void cf7::updateUI (QString text)
    {
    .... UpdateLabels (text);
    }
    @

    of course im am getting UpdateLabels() was not declared in this scope

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #4

      To update a label uncomment the following connect in c7 constructor.
      @
      connect(this, SIGNAL(updateUI(QString)),parent, SLOT(UpdateLabels(QString)));
      @

      You don't need to define void cf7::updateUI(QString text) in cf7.cpp.
      Just declare it as a signal, which you already did.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #5

        <DELETED>

        1 Reply Last reply
        0
        • J Offline
          J Offline
          joker_hr
          wrote on last edited by
          #6

          it works
          thank you

          1 Reply Last reply
          0
          • J Offline
            J Offline
            joker_hr
            wrote on last edited by
            #7

            this is great, old program(with minor changes) just in two days becomes new program.
            this Qt is great work!

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

              You should just make a correction: connect your c7 updateUI signal in your MainWindow's constructor rather than in c7's constructor. It will make c7 completely independent of the GUI on top of it.

              Also from a pure reading point of view, you should add the missing emit keyword, it will make your code easier to understand

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

                what I need to run application on platform with just framebuffer, I am little confused here. Is there some sort Qt server like X server or do I need install framework on target machine?

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

                  What version of Qt are you using ?

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

                    it is standard package of fedora 19, version 3.0

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

                      I meant for your target

                      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
                      • J Offline
                        J Offline
                        joker_hr
                        wrote on last edited by
                        #13

                        I am not using anything yet :)
                        question
                        For using with X11 I will install * Qt libraries 4.8.5 for Linux/X11 *
                        and for using directly to framebuffer i will install Qt libraries 4.8.5 for embedded Linux?
                        How applications behave with static build on linux targets?

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

                          Pretty much it's that yes. Depending on what you will run on your target, you might need to compile Qt yourself.

                          I don't exactly understand your question about static application behavior

                          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
                          • J Offline
                            J Offline
                            joker_hr
                            wrote on last edited by
                            #15

                            I thought about static compiling of executable file that has all necessary libs inside.

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

                              The application behavior won't change because of the build type. However you should first check that you can use a static build, there are licenses implication with it.

                              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

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved