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. Problem with connect with object created dynamically
Qt 6.11 is out! See what's new in the release blog

Problem with connect with object created dynamically

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 577 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by VRonin
    #1

    I have a class that emit a signal in this way:

    void CustomTracer::mouseMoveEvent(QMouseEvent *event)
    {
        /* let the crosshair cursor follow the mouse position */
    
        if (click_right == BTN_FALSE)
        {
        if(!mouseMarkerX) mouseMarkerX = new QCPItemStraightLine(this);
        if(!mouseMarkerY) mouseMarkerY = new QCPItemStraightLine(this);
    
         positionX = xAxis->pixelToCoord( event->pos().x() );
    
        emit sign_tracer_bis();
    }
    

    in MainWindow:

    void MainWindow::Altezza_LdC_Acq()
    {
        QDockWidget *dock = new QDockWidget;
        dock->setMinimumWidth(500);
        dock->setMaximumWidth(500);
        dock->setMinimumHeight(500);
        dock->setMaximumHeight(500);
    
        Altezza_acq_bis = new CustomTracer(dock);
        Altezza_acq_bis->resize(500,500);
        graph_Acq_bis = Altezza_acq_bis->addGraph();
        double a;
        double b;
        double m;
        double n;
        a= ui->Grafico_Altezza_LdC_Acquisizione->x1;
        b= ui->Grafico_Altezza_LdC_Acquisizione->x2;
        m= ui->Grafico_Altezza_LdC_Acquisizione->y1;
        n= ui->Grafico_Altezza_LdC_Acquisizione->y2;
        Altezza_acq_bis->xAxis->setRange(a,b);
        Altezza_acq_bis->yAxis->setRange(m,n);
        graph_Acq_bis->setData(graph2->data());
    
        dock->setFloating(true);
        dock->show();
    
        QObject::connect(Altezza_acq_bis,SIGNAL(sign_tracer_bis()),this,SLOT(Tracer_Acq()));
    }
    

    and the slot is:

    
    void MainWindow::Tracer_Acq()
    
    {
    
        double x = (Altezza_acq_bis->positionX);
        int j;
        double u;
        double posX;
    
    
        QString h = QString::number(x,'f',2);
        double x1 = h.toDouble();
        for (int i=0; i<1000; i++)
        {
            if  (abs(xalt[i] - x1) <0.001)
            {
    
               u= xalt[i];
               j=i;
    
               Altezza_acq_bis->positionY = f_altezza[j];
               posX = xalt[j];
               if((Altezza_acq_bis->mouseMarkerX) && (Altezza_acq_bis->mouseMarkerY))
    
               {
                  Altezza_acq_bis->mouseMarkerX->point1->setCoords(Altezza_acq_bis->positionX, 0);//VERTICALE
                  Altezza_acq_bis->mouseMarkerX->point2->setCoords(Altezza_acq_bis->positionX, 1);//VERTICALE
                  Altezza_acq_bis->mouseMarkerY->point1->setCoords(0,Altezza_acq_bis->positionY);//ORIZZONTALE
                  Altezza_acq_bis->mouseMarkerY->point2->setCoords(1, Altezza_acq_bis->positionY);//ORIZZONTALE
    
    
                  QString x_text = QString::number(Altezza_acq_bis->positionX,'f',2);
                  QString y_text = QString::number(Altezza_acq_bis->positionY);
    
                  QString coord_p = QString("%1, %2").arg(x_text,y_text);
                  QCursor cursor;
                  QToolTip::showText(cursor.pos(),coord_p,this,QRect(),2000);
    
               }}
    
    
            }
               Altezza_acq_bis->replot();
         }
    
    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      What is the problem?
      First thing to try is replacing QObject::connect(Altezza_acq_bis,SIGNAL(sign_tracer_bis()),this,SLOT(Tracer_Acq())); with QObject::connect(Altezza_acq_bis,&CustomTracer::sign_tracer_bis,this,&MainWindow::Tracer_Acq);

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      ? 1 Reply Last reply
      2
      • VRoninV VRonin

        What is the problem?
        First thing to try is replacing QObject::connect(Altezza_acq_bis,SIGNAL(sign_tracer_bis()),this,SLOT(Tracer_Acq())); with QObject::connect(Altezza_acq_bis,&CustomTracer::sign_tracer_bis,this,&MainWindow::Tracer_Acq);

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @VRonin said in Problem with connect with object created dynamically:

        QObject::connect(Altezza_acq_bis,&CustomTracer::sign_tracer_bis,this,&MainWindow::Tracer_Acq);

        thanks very much!!! I wrote bad the connect...now it's ok!! thanks

        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