I have an application with a map, when I click on a map, I draw a Waypoint and save it to my struct WaypointData

Draw a Waypoint to the map

 int MapViewClass::view_ObjectCallback(GlsMapView* self, DisplayEvent* ev) { Vector lonlatalt; _pickedLocation.GetGeodetic(&lonlatalt); WaypointData* w = new WaypointData(); w->iD = 0; w->state = 0; w->lng = lonlatalt.x; w->lat = lonlatalt.y; w->alt = lonlatalt.z; int iconType = 0; w->iconId = symbols->AddIcon(_pickedLocation,iconType); short nN = _dtedMapChartSource.GetElevationDataPoint(_pickedLocation); symbols->GetIcon(w->iconId)->SetResource("State", std::to_string(w->state).c_str()); symbols->GetIcon(w->iconId)->SetResource("ID", std::to_string(w->iD).c_str()); //Set Elevation Data symbols->GetIcon(w->iconId)->SetResource("NN", std::to_string(nN).c_str()); //Set Height over Ground symbols->GetIcon(w->iconId)->SetResource("Height", std::to_string(w->alt).c_str()); AddPathPoint(_pickedLocation); waypointData.push_back(*w); MainWindow *_MainWindor = new MainWindow(); _MainWindor->PMission_BKS(w); } 

my struckt

 struct WaypointData { short iD; short iconId; double lng; double lat; double alt; int minAltitude; int state; }; 

All this is in my

 namespace disti { class MapViewClass : public ComponentBase { public: 

In the same function where the Waypoint is drawn, a function is called from MainWindow

 MainWindow *_MainWindor = new MainWindow(); _MainWindor->PMission_BKS(w); 

The PMission_BKS function is in public in

 namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { 

Here is my PMission_BKS function

 void MainWindow::PMission_BKS(WaypointData* w) { std::stringstream str; str << w->lng; ui->PMission_uberschrift->setText(str.str().c_str()); } 

The problem is the following if I try to call qDebug() << w->lng; then I get the value for example 10.5112 , but if I try to print the text in QLabel or QPlainText then I just don’t see anything

  • Why these perversions with the buffer and std :: string? You already have ready-made wrappers, do not invent your crutches: ui-> PMission_uberschrift-> setText (QString :: number (w-> lng)); - test123
  • I recommend reading about std :: shared_ptr and std :: unique_ptr - test123

1 answer 1

The code can not be accurately said, but there is an assumption that the problem is in this place:

 MainWindow *_MainWindor = new MainWindow(); _MainWindor->PMission_BKS(w); 

Give the code where this part is used.

There is a suspicion that you create somewhere an instance of MainWindow, which you display on the screen, and in the above code, instead of using the existing MainWindow, you create a new one and call PMission_BKS for it, and there, even the value is set correctly QLabel, but this form is not displayed on the screen and you do not see the change

  • The code is here. Вот так выглядит моя функция PMission_BKS . The question then is, how do I use parts from MainWindow in MapViewClass if MapViewClass already declared in MainWindow ? Ie in mainwindow.h disti::MapViewClass *MapView; - Insider
  • @Insider, you have the event code, but there is no code that causes this event. There is only the creation of an instance of the form in the heap and passing it a parameter, but what is created and used in the heap is not clear. Give the full code. Is the content of the main function? - test123
  • @ test123 corrected the question. PMission_BKS in the main function, the rest in MapViewClass - Insider
  • @Insider, >> a function is called from MainWindow. << means Alexander is right. You do some nonsense. What is called from MainWindow should not create a new MainWindow. Use this. - test123
  • @ test123 never worked with this. Is there an example? - Insider