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. How to include .txt on Qt

How to include .txt on Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
196 Posts 11 Posters 196.5k Views 3 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.
  • P Offline
    P Offline
    Payx
    wrote on last edited by
    #57

    I defined my QMap here :

    QMap<QRgb, CostInfo > Costs = {
    	{ QColor(255 , 0 , 0 ).rgb(), { "://fraise.png", 10 }},
    	{ QColor(0 , 255 , 0 ).rgb(), { "://balleverte.png", 20 }},
    	{ QColor(0 , 0 , 255 ).rgb(), { "://ballebleue.png", 20 }},
    	{ QColor(255 , 255 , 255 ).rgb(), { "://balleblanche.png", 20 }},
    	{ QColor(255 , 128 , 0 ).rgb(), { "://ballepeche.png", 20 }},
    	{ QColor(0 , 0 , 0 ).rgb(), { "://noir.png", 20 }},
    	{ QColor(102 , 51 , 0 ).rgb(), { "://marron.png", 20 }},
    	{ QColor(255 , 102 , 78 ).rgb(), { "://rose.png", 20 }},
    	{ QColor(0 , 204 , 204 ).rgb(), { "://turquoise.png", 20 }},
    	{ QColor(255 , 178 , 102 ).rgb(), { "://beige.png", 20 }},
    	{ QColor(76 , 0 , 153 ).rgb(), { "://violet.png", 20 }},
    	{ QColor(100 , 100 , 100 ).rgb(), { "://gris.png", 20 }},
    };
    

    And this is a function call no ?

    QMapIterator<QRgb, CostInfo>i;
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #58

      Hi
      And where is the definition for CostInfo ?

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Payx
        wrote on last edited by
        #59

        i do not know, i thought CostInfo is the cost near the picture so i didnt needed to defined it no ?

        FlotisableF 1 Reply Last reply
        0
        • P Payx

          i do not know, i thought CostInfo is the cost near the picture so i didnt needed to defined it no ?

          FlotisableF Offline
          FlotisableF Offline
          Flotisable
          wrote on last edited by
          #60

          @Payx
          the compiler only knows the fundamental types or types defined.
          so you need to define CostInfo or compiler will give you an error.

          P 1 Reply Last reply
          0
          • FlotisableF Flotisable

            @Payx
            the compiler only knows the fundamental types or types defined.
            so you need to define CostInfo or compiler will give you an error.

            P Offline
            P Offline
            Payx
            wrote on last edited by
            #61

            @Flotisable Thank you,

            so i have to define CostInfo as an int ?

            FlotisableF 1 Reply Last reply
            0
            • P Payx

              @Flotisable Thank you,

              so i have to define CostInfo as an int ?

              FlotisableF Offline
              FlotisableF Offline
              Flotisable
              wrote on last edited by Flotisable
              #62

              @Payx
              in your case, one of the value you give is { "://fraise.png", 10 }, which is composed of a string and a integer

              it seems CostInfo should look like this

              struct CostInfo
              {
                QString imageName;
                int     cost;
              };
              
              1 Reply Last reply
              1
              • P Offline
                P Offline
                Payx
                wrote on last edited by
                #63

                Okay understood how it works now.

                Why it say that "Costs" is not declared, it is the name of the QMap right ?

                mrjjM 1 Reply Last reply
                0
                • P Payx

                  Okay understood how it works now.

                  Why it say that "Costs" is not declared, it is the name of the QMap right ?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #64

                  @Payx
                  Yes Costs is the QMap variable.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Payx
                    wrote on last edited by
                    #65

                    How do i declare a QMap ?

                    i tried

                    QMap<QRgb, CostInfo > Costs;
                    
                    mrjjM 1 Reply Last reply
                    0
                    • P Payx

                      How do i declare a QMap ?

                      i tried

                      QMap<QRgb, CostInfo > Costs;
                      
                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #66

                      @Payx
                      Yes that is how you declare an empty QMap called Costs.

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        Payx
                        wrote on last edited by
                        #67

                        Yes but it say that CostInfo is not declared again

                        mrjjM 1 Reply Last reply
                        0
                        • P Payx

                          Yes but it say that CostInfo is not declared again

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #68

                          @Payx
                          CostInfo must be declared before you use it in QMap
                          Where is it?
                          you used to have struct CostInfo declaration.

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            Payx
                            wrote on last edited by
                            #69

                            I put my declaration of CostInfo in my .h

                            mrjjM 1 Reply Last reply
                            0
                            • P Payx

                              I put my declaration of CostInfo in my .h

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #70

                              @Payx
                              and is that .h file included in the same file where u have the Qmap def ?

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                Payx
                                wrote on last edited by
                                #71

                                i got

                                QMap<QRgb, CostInfo > Costs = {
                                	{ QColor(255 , 0 , 0 ).rgb(), { "://fraise.png", 10 }},
                                	{ QColor(0 , 255 , 0 ).rgb(), { "://balleverte.png", 20 }},
                                	{ QColor(0 , 0 , 255 ).rgb(), { "://ballebleue.png", 20 }},
                                	{ QColor(255 , 255 , 255 ).rgb(), { "://balleblanche.png", 20 }},
                                	{ QColor(255 , 128 , 0 ).rgb(), { "://ballepeche.png", 20 }},
                                	{ QColor(0 , 0 , 0 ).rgb(), { "://noir.png", 20 }},
                                	{ QColor(102 , 51 , 0 ).rgb(), { "://marron.png", 20 }},
                                	{ QColor(255 , 102 , 78 ).rgb(), { "://rose.png", 20 }},
                                	{ QColor(0 , 204 , 204 ).rgb(), { "://turquoise.png", 20 }},
                                	{ QColor(255 , 178 , 102 ).rgb(), { "://beige.png", 20 }},
                                	{ QColor(76 , 0 , 153 ).rgb(), { "://violet.png", 20 }},
                                	{ QColor(100 , 100 , 100 ).rgb(), { "://gris.png", 20 }},
                                };
                                

                                in my .cpp

                                and struct in my .h,

                                do i paste "QMap<QRgb, CostInfo > Costs;" in my .cpp like my function or in my .h (sorry but i didnt understand ur question ^^)

                                mrjjM 1 Reply Last reply
                                0
                                • P Payx

                                  i got

                                  QMap<QRgb, CostInfo > Costs = {
                                  	{ QColor(255 , 0 , 0 ).rgb(), { "://fraise.png", 10 }},
                                  	{ QColor(0 , 255 , 0 ).rgb(), { "://balleverte.png", 20 }},
                                  	{ QColor(0 , 0 , 255 ).rgb(), { "://ballebleue.png", 20 }},
                                  	{ QColor(255 , 255 , 255 ).rgb(), { "://balleblanche.png", 20 }},
                                  	{ QColor(255 , 128 , 0 ).rgb(), { "://ballepeche.png", 20 }},
                                  	{ QColor(0 , 0 , 0 ).rgb(), { "://noir.png", 20 }},
                                  	{ QColor(102 , 51 , 0 ).rgb(), { "://marron.png", 20 }},
                                  	{ QColor(255 , 102 , 78 ).rgb(), { "://rose.png", 20 }},
                                  	{ QColor(0 , 204 , 204 ).rgb(), { "://turquoise.png", 20 }},
                                  	{ QColor(255 , 178 , 102 ).rgb(), { "://beige.png", 20 }},
                                  	{ QColor(76 , 0 , 153 ).rgb(), { "://violet.png", 20 }},
                                  	{ QColor(100 , 100 , 100 ).rgb(), { "://gris.png", 20 }},
                                  };
                                  

                                  in my .cpp

                                  and struct in my .h,

                                  do i paste "QMap<QRgb, CostInfo > Costs;" in my .cpp like my function or in my .h (sorry but i didnt understand ur question ^^)

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #72

                                  @Payx
                                  it sounds right.

                                  The CostInfo is in .h ?

                                  Can you show it ?

                                  1 Reply Last reply
                                  0
                                  • P Offline
                                    P Offline
                                    Payx
                                    wrote on last edited by Payx
                                    #73

                                    i think i fixed it i had :

                                    #ifndef MAINWINDOW_H
                                    #define MAINWINDOW_H
                                    
                                    #include <QMainWindow>
                                    #include <QPixmap>
                                    #include <QPoint>
                                    #include <QSize>
                                    #include <iostream>
                                    
                                    namespace Ui {
                                    	class MainWindow;
                                    }
                                    
                                    class MainWindow : public QMainWindow
                                    {
                                    	Q_OBJECT
                                    
                                    public:
                                    	explicit MainWindow(QWidget *parent = 0);
                                    	struct CostInfo
                                    	{
                                    		QString ImageName;
                                    		int     cost;
                                    	};
                                    
                                    
                                    
                                    	~MainWindow();
                                    
                                    
                                    
                                    
                                    
                                    private slots:
                                    	void on_push_clicked();
                                    	void on_push2_clicked();
                                    
                                    	void on_verticalSlider_sliderMoved(int position);
                                    
                                    	void on_verticalSlider_actionTriggered(int action);
                                    
                                    private:
                                    	Ui::MainWindow *ui;
                                    	QImage pixi;
                                    	QPixmap pixa;
                                    	float k;
                                    	int a;
                                    
                                    
                                    	int z=1;
                                    	int b;
                                    };
                                    
                                    #endif // MAINWINDOW_H
                                    

                                    and now i remember that i have to paste in the .h but not in public or private so i have :

                                    #ifndef MAINWINDOW_H
                                    #define MAINWINDOW_H
                                    
                                    #include <QMainWindow>
                                    #include <QPixmap>
                                    #include <QPoint>
                                    #include <QSize>
                                    #include <iostream>
                                    
                                    namespace Ui {
                                    	class MainWindow;
                                    }
                                    struct CostInfo
                                    {
                                    	QString ImageName;
                                    	int     cost;
                                    };
                                    
                                    
                                    class MainWindow : public QMainWindow
                                    {
                                    	Q_OBJECT
                                    
                                    public:
                                    	explicit MainWindow(QWidget *parent = 0);
                                    
                                    
                                    
                                    	~MainWindow();
                                    
                                    
                                    
                                    
                                    
                                    private slots:
                                    	void on_push_clicked();
                                    	void on_push2_clicked();
                                    
                                    
                                    	void on_verticalSlider_sliderMoved(int position);
                                    
                                    	void on_verticalSlider_actionTriggered(int action);
                                    
                                    private:
                                    	Ui::MainWindow *ui;
                                    	QImage pixi;
                                    	QPixmap pixa;
                                    	float k;
                                    	int a;
                                    
                                    
                                    	int z=1;
                                    	int b;
                                    };
                                    
                                    #endif // MAINWINDOW_H
                                    

                                    and what is this line :

                                    QMapIterator<QRgb, CostInfo> i;
                                    

                                    because it say "no matching function to call"

                                    1 Reply Last reply
                                    0
                                    • mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #74

                                      I wonder if you dont have c++11 compiler.

                                      "no matching function to call"
                                      Make sure you have included QMapIterator

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        Payx
                                        wrote on last edited by
                                        #75

                                        i included, no change.

                                        How can i see if i have a c++ compiler ?

                                        mrjjM 1 Reply Last reply
                                        1
                                        • P Payx

                                          i included, no change.

                                          How can i see if i have a c++ compiler ?

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by mrjj
                                          #76

                                          @Payx
                                          Ok. No sure what goes wrongly for you. Seems to have CostInfo
                                          in .h and Costs QMap in cpp which should be fine.

                                          • How can i see if i have a c++ compiler ?
                                            c++11 compiler. Meaning a compiler that knows the new c++11 version.
                                            I assume you do. But if you are on linux or using old Qt it might not be the case.

                                          So what platform and Qt version?

                                          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