Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    [C++ wxWidgets] Estrarre il valore di una wxtextCtrl in un const char*

    Salve, ho un problema con il controllo wxtextCtrl. Avrei bisogno di estrarre il valore in questa casella di testo e convertirlo in un const char* per poterlo passare ad un metodo di una classe. Mi dareste una mano voi?

    Ho provato così:
    codice:
    wxString temp = m_textCtrl1->GetLineText(0);
    const char* path = (const char*)temp.mb_str(wxConvUTF8);
    
    // per leggere il valore (riconverto da const char* a wxString)
    wxMessageBox(wxString(path, wxConvUTF8), wxString("Errore", wxConvUTF8), wxICON_ERROR);
    // ma mi ritorna caratteri strani intervallati da pezzi della mia stringa o proprio nulla
    
    // mentre se uso questa funzione
    wxMessageBox(temp, wxString("Errore", wxConvUTF8), wxICON_ERROR);
    // mi ritorna il valore giusto
    
    classe.funzione(path,m_spinCtrl1->GetValue()); // prototipo classe::funzione(const char* path, int val)
    
    // se stampo il valore ricevuto nel metodo ottengo lo stesso un valore sballato o nullo
    bool classe::funzione(const char* path, int val)
    {
         std::fstream file(_filepath, ios::in);
         if(!file.is_open())
         {
              wxMessageBox(wxString(path, wxConvUTF8), wxString("Errore", wxConvUTF8), wxICON_ERROR);
         {
         ...
    }
    grazie mille
    by Palomo2

  2. #2

  3. #3
    ho provato anche con il metodo toAscii() ma niente da fare. Alla fine ho risolto semplicemente passando direttamente "temp.mb_str(wxConvUTF8)" alla funzione:

    codice:
    wxString temp = m_textCtrl1->GetLineText(0);
    //const char* path = (const char*)temp.mb_str(wxConvUTF8);
    
    // per leggere il valore (riconverto da const char* a wxString)
    wxMessageBox(wxString(temp.mb_str(wxConvUTF8), wxConvUTF8), wxString("Errore", wxConvUTF8), wxICON_ERROR);
    
    classe.funzione(temp.mb_str(wxConvUTF8),m_spinCtrl1->GetValue()); // prototipo classe::funzione(const char* path, int val)
    Non so cosa è cambiato ma così va...
    by Palomo2

  4. #4
    Hai provato a chiamare il metodo c_str() sul risultato della chiamata del metodo GetValue() della wxTextCtrl ?
    char *tmp = (txt->GetValue()).c_str(); //txt è un puntatore a wxTextCtrl naturalmente
    Experience is what you get when you don’t get what you want

  5. #5
    ho provato anche con il "c_str()" ma ho avuto lo stesso risultato...
    by Palomo2

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.