In the recent past, wireless sensor networks (WSN) have been used in a wide variety of applications which have special properties and requirements. In this study, a novel version of quantum-inspired gravitational search algorithm is presented as a new optimization methodology which is well suitable for quadrivalent encoded problems. The proposed method is adapted in a wireless sensor network in precise agriculture application to find an optimal and adaptive design of wireless sensor network to improve the energy consumption and extend the life span of the network, taking into consideration the communication limitations and application-specific requirements. The performance of the proposed method which is called QQIGSA is compared with the binary genetic algorithm (BGA) and binary particle optimization (BPSO). The experimental results indicate that the WSN designed by QQIGSA has the most performance in fulfilling the requirements and prolonging the lifetime of the network.